<?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 : Entity State Change before entity add to manager</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Entity State Change before entity add to manager</description>
  <pubDate>Wed, 10 Jun 2026 20:48:07 -700</pubDate>
  <lastBuildDate>Thu, 16 Sep 2010 14:21:54 -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=2165</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>Entity State Change before entity add to manager : Hi Blaine;Yes, what you are observing...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2165&amp;PID=8534#8534</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> 2165<br /><strong>Posted:</strong> 16-Sep-2010 at 2:21pm<br /><br />Hi Blaine;<div><br></div><div>Yes, what you are observing is by design. An entity is automatically added if any of its related entities are already in the EntityManager.</div>]]>
   </description>
   <pubDate>Thu, 16 Sep 2010 14:21:54 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2165&amp;PID=8534#8534</guid>
  </item> 
  <item>
   <title>Entity State Change before entity add to manager : Hello Everyone    I am seeing...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2165&amp;PID=8530#8530</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=873" rel="nofollow">bstearns</a><br /><strong>Subject:</strong> 2165<br /><strong>Posted:</strong> 16-Sep-2010 at 11:22am<br /><br /><DIV><PRE style="FONT-FAMILY: c&#111;nsolas"><FONT face="Courier New"><FONT face="Times New Roman, Times, serif" size=3>Hello Everyone </FONT></PRE></DIV><DIV><DIV style="MARGIN: 0.75pt 1.5pt; LINE-HEIGHT: normal"><FONT face="Times New Roman, Times, serif" size=3></FONT></DIV><DIV style="MARGIN: 0.75pt 1.5pt; LINE-HEIGHT: normal"><FONT face="Times New Roman, Times, serif" size=3>I am seeing something with my entity manager when adding a new entity that doesn't make sense to me.</FONT></DIV><DIV style="MARGIN: 0.75pt 1.5pt; LINE-HEIGHT: normal"><FONT face="Times New Roman, Times, serif" size=3>From all my reading it seems that when I call&nbsp;</FONT></DIV><DIV style="MARGIN: 0.75pt 1.5pt; LINE-HEIGHT: normal">&nbsp;</DIV><DIV style="MARGIN: 0.75pt 1.5pt; LINE-HEIGHT: normal">X&nbsp;foo&nbsp;= EntityManger.CreateEntity&lt;X&gt;();&nbsp;</DIV><DIV style="MARGIN: 0.75pt 1.5pt; LINE-HEIGHT: normal">&nbsp;</DIV><DIV style="MARGIN: 0.75pt 1.5pt; LINE-HEIGHT: normal"><FONT face="Times New Roman, Times, serif" size=3>I will get a new instance of the entity of type X and its entity state will be detatched until I explicity call EntityManager.AddEntity(foo).</FONT></DIV><DIV style="MARGIN: 0.75pt 1.5pt; LINE-HEIGHT: normal">&nbsp;</DIV><DIV style="MARGIN: 0.75pt 1.5pt; LINE-HEIGHT: normal"><FONT face="Times New Roman, Times, serif" size=3>This is exactly how it works if my type X does not have property of another type on it.&nbsp; The propblem seems to happen when I have a type X that has a property of type Y in it.&nbsp; Then when I set the Type Y property the entity state then changes to added and if I look at the EntityManager.Xs I see the entity already attached there. </FONT></DIV><DIV style="MARGIN: 0.75pt 1.5pt; LINE-HEIGHT: normal">&nbsp;</DIV><DIV style="MARGIN: 0.75pt 1.5pt; LINE-HEIGHT: normal"><FONT face="Times New Roman, Times, serif" size=3>To try and illustrate this better here is my code:</FONT></DIV><DIV style="MARGIN: 0.75pt 1.5pt 0.75pt 0.5in; LINE-HEIGHT: normal"><BR>TypeX&nbsp;foo=&nbsp;EntMan.CreateEntity&lt;TypeX&nbsp;&gt;();<BR>&nbsp;<BR><strong>//at this point foo has an entitystate = detatched and EntMan.TypeXs does not contain anything</strong><BR>foo.FooID&nbsp;=&nbsp;Guid.NewGuid();<BR>foo.SomeProp1&nbsp;=&nbsp;"Something";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><strong>//bar is a type that is already in cache and has an entity state = unchanged</strong><BR>foo.SomePropThatIsOfOtherTypeInCache =&nbsp;bar;</DIV><DIV style="MARGIN: 0in 1.5pt 0.75pt 0.5in; LINE-HEIGHT: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"><strong>//after setting SomePropThatIsOfOtherTypeInCache we can see that </strong></DIV><DIV style="MARGIN: 0in 1.5pt 0.75pt 0.5in; LINE-HEIGHT: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"><strong>//foo.entitystate = added and EntMan.TypeXs now conatins the foo entity.</strong></DIV><DIV style="MARGIN: 0in 1.5pt 0.75pt 0in; LINE-HEIGHT: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"><strong>&nbsp;</strong></DIV><DIV style="MARGIN: 0in 1.5pt 0.75pt 0in; LINE-HEIGHT: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"><FONT face="Times New Roman, Times, serif" size=3>At this point because the entitystate is added and the entitymanager already contains the entity there is no reason to call EntityManager.AddEntity(foo).</FONT></DIV><DIV style="MARGIN: 0in 1.5pt 0.75pt 0in; LINE-HEIGHT: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"><FONT face="Times New Roman, Times, serif" size=3>&nbsp;</FONT></DIV><DIV style="MARGIN: 0in 1.5pt 0.75pt 0in; LINE-HEIGHT: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"><FONT face="Times New Roman, Times, serif" size=3>I cannot find any documentation that mentions this functionality.&nbsp; Is this by design or do I not understand how this is suppose to work.</FONT></DIV><DIV style="MARGIN: 0in 1.5pt 0.75pt 0in; LINE-HEIGHT: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"><FONT face="Times New Roman, Times, serif" size=3></FONT>&nbsp;</DIV><DIV style="MARGIN: 0in 1.5pt 0.75pt 0in; LINE-HEIGHT: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"><FONT face="Times New Roman, Times, serif" size=3>Thanks</FONT></DIV><DIV style="MARGIN: 0in 1.5pt 0.75pt 0in; LINE-HEIGHT: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"><FONT face="Times New Roman, Times, serif" size=3>Blaine</FONT></DIV></FONT></DIV>]]>
   </description>
   <pubDate>Thu, 16 Sep 2010 11:22:17 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2165&amp;PID=8530#8530</guid>
  </item> 
 </channel>
</rss>