<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : Unexpected behavior in AttachEntity</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Unexpected behavior in AttachEntity</description>
  <pubDate>Mon, 13 Apr 2026 16:14:46 -700</pubDate>
  <lastBuildDate>Tue, 01 Mar 2011 13:07:07 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=2535</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>Unexpected behavior in AttachEntity : Hi smi-mark;The AttachEntity is...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2535&amp;PID=10091#10091</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=912" rel="nofollow">DenisK</a><br /><strong>Subject:</strong> 2535<br /><strong>Posted:</strong> 01-Mar-2011 at 1:07pm<br /><br /><div style=": rgb255, 255, 255; margin-left: 1px; margin-top: 1px; margin-right: 1px; margin-bottom: 1px; font-family: Verdana, Arial, Helvetica, sans-serif; color: rgb0, 0, 0; font-weight: normal; font-size: 12px; line-height: 1.4; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; -: n&#111;ne; ">Hi smi-mark;<div><br></div><div>The AttachEntity is the expected behavior. As the API says, it will only add a detached entity and change its state to an Unchanged state. The entity will be ignored if it already belongs to that EntityManager or an exception will be thrown if you're trying to attach an entity that already belongs to another EntityManager.</div></div>]]>
   </description>
   <pubDate>Tue, 01 Mar 2011 13:07:07 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2535&amp;PID=10091#10091</guid>
  </item> 
  <item>
   <title>Unexpected behavior in AttachEntity : Hi smi-mark;If you&amp;#039;re assigning...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2535&amp;PID=10090#10090</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=912" rel="nofollow">DenisK</a><br /><strong>Subject:</strong> 2535<br /><strong>Posted:</strong> 01-Mar-2011 at 12:51pm<br /><br /><div style=": rgb255, 255, 255; margin-left: 1px; margin-top: 1px; margin-right: 1px; margin-bottom: 1px; font-family: Verdana, Arial, Helvetica, sans-serif; color: rgb0, 0, 0; font-weight: normal; font-size: 12px; line-height: 1.4; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; -: n&#111;ne; ">Hi smi-mark;<div><br></div><div>If you're assigning contact.Account to an "account" entity that is already attached to an EntityManager, then "contact" will automatically be added to that EntityManager as well.&nbsp;</div><div><br></div><div>The AttachEntity seems to change an entity's state to Unchanged when the entity is still Detached. But when the entity's state is Added, the AttachEntity call seems to not change the entity's state as you observed. I have to confirm this one with one of the lead developers to see if this is the expected behavior and get back to you.</div><div><br></div><div>I couldn't repro your issue with the fake composition context having no original values map. Could you give me a code snippet showing how you create and populate the fake EM? Please give me the DevForce version you're using as well.</div></div>]]>
   </description>
   <pubDate>Tue, 01 Mar 2011 12:51:22 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2535&amp;PID=10090#10090</guid>
  </item> 
  <item>
   <title>Unexpected behavior in AttachEntity : I thought using a fake composition...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2535&amp;PID=10088#10088</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=449" rel="nofollow">smi-mark</a><br /><strong>Subject:</strong> 2535<br /><strong>Posted:</strong> 28-Feb-2011 at 8:25pm<br /><br />I thought using a fake composition context might bypass this, which it seems to have done, but I found another issue.<br><br>Something is very strange because using this with a fake composition context, there is no original value map.<br><br>This would all work fine, I'm sure, if it was from a database, but right now I am working in model first, there is no database as such.<br><br>I was able to "fix" it by creating a simple console app and overriding the EntityState and original value map and then save the cache state, which the SL app now reads and works fine with.<br><br>Perhaps I'm just doing something wrong, but the behavior seems a little weird.<br>]]>
   </description>
   <pubDate>Mon, 28 Feb 2011 20:25:22 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2535&amp;PID=10088#10088</guid>
  </item> 
  <item>
   <title>Unexpected behavior in AttachEntity :  According to the documentation,...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2535&amp;PID=10087#10087</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=449" rel="nofollow">smi-mark</a><br /><strong>Subject:</strong> 2535<br /><strong>Posted:</strong> 28-Feb-2011 at 1:03pm<br /><br />According to the documentation, calling CreateEntity should result in a detached entity, and it should stay detatched until AddToManager or AttachEntity is called. Setting a relation property causes it to be 'added'. See below:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private AccountContact AddAccountContact(EntityManager manager, Account account, string name, string email)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var contact = manager.CreateEntity&lt;AccountContact&gt;();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; contact.AccountContactId = Guid.NewGuid(); // Detached (correct)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; contact.Account =account; //Added (invalid)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; contact.Name = name;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; contact.EmailAddress = email;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; manager.AttachEntity(contact); //Stays as "Added" rather than unmodified.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return contact;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>Is this the expected behavior? I am using this as sample data so I don't really want it to show as Added.<br><br>It looks like ScalarEntityReference.SetEntity is calling "AttachIfPossible" which is adding it to the manager rather than keeping it in a detached state.<br><span style="font-size:10px"><br /><br />Edited by smi-mark - 28-Feb-2011 at 1:10pm</span>]]>
   </description>
   <pubDate>Mon, 28 Feb 2011 13:03:34 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2535&amp;PID=10087#10087</guid>
  </item> 
 </channel>
</rss>