<?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 : Null Entity Incorrectly Attached</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Null Entity Incorrectly Attached</description>
  <pubDate>Wed, 13 May 2026 21:40:28 -700</pubDate>
  <lastBuildDate>Wed, 31 Aug 2011 10:39:19 -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=2929</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>Null Entity Incorrectly Attached :    Ian,It looks like I will...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2929&amp;PID=11607#11607</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=892" rel="nofollow">sbelini</a><br /><strong>Subject:</strong> 2929<br /><strong>Posted:</strong> 31-Aug-2011 at 10:39am<br /><br />Ian,<div>&nbsp;</div><div>It looks like I will need a reproducible solution from you as I could not repro it here.</div><div>&nbsp;</div><div>I've used <em><strong>Orders *_0..1 Employee</strong></em> and <em><strong>Employee1 *_0..1 Employee2</strong></em> from NorthwindIB to test:</div><div>&nbsp;</div><div>&nbsp;</div><div><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas">var</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas"> mgr = </font></font><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas">new</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas"> </font></font><font color="#2b91af" size="2" face="C&#111;nsolas"><font color="#2b91af" size="2" face="C&#111;nsolas"><font color="#2b91af" size="2" face="C&#111;nsolas">NorthwindIBEntities</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas">();</font></font></div><div><font size="2" face="C&#111;nsolas"></font>&nbsp;</div><div><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas">var</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas"> employee = </font></font><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas">new</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas"> </font></font><font color="#2b91af" size="2" face="C&#111;nsolas"><font color="#2b91af" size="2" face="C&#111;nsolas"><font color="#2b91af" size="2" face="C&#111;nsolas">Employee</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas">();</font></font></div><div><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas">mgr.AddEntity(employee);</font></font></div><div><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas">var</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas"> employee2EntityState = employee.Employee2.EntityAspect.EntityState; </font></font><font color="#008000" size="2" face="C&#111;nsolas"><font color="#008000" size="2" face="C&#111;nsolas"><font color="#008000" size="2" face="C&#111;nsolas">// employee2EntityState is Detached</font></font></font></div><div><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas">var</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas"> isNullEmployee2 = employee.Employee2.EntityAspect.IsNullEntity; </font></font><font color="#008000" size="2" face="C&#111;nsolas"><font color="#008000" size="2" face="C&#111;nsolas"><font color="#008000" size="2" face="C&#111;nsolas">// isNullEmployee2 is true</font></font></font></div><div><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas"></font></font>&nbsp;</div><div><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas">mgr.Clear();</font></font></div><div><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas"></font></font></font>&nbsp;</div><div><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas">var</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas"> order = </font></font><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas">new</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas"> </font></font><font color="#2b91af" size="2" face="C&#111;nsolas"><font color="#2b91af" size="2" face="C&#111;nsolas"><font color="#2b91af" size="2" face="C&#111;nsolas">Order</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas">();</font></font></div><div><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas">mgr.AddEntity(order);</font></font></div><div><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas">var</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas"> employeeEntityState = order.Employee.EntityAspect.EntityState; </font></font><font color="#008000" size="2" face="C&#111;nsolas"><font color="#008000" size="2" face="C&#111;nsolas"><font color="#008000" size="2" face="C&#111;nsolas">// employeeEntityState is Detached</font></font></font></div><div><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas">var</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas"> isNullEmployee = order.Employee.EntityAspect.IsNullEntity; </font></font><font color="#008000" size="2" face="C&#111;nsolas"><font color="#008000" size="2" face="C&#111;nsolas"><font color="#008000" size="2" face="C&#111;nsolas">// isNullEmployee is true</font></font></font></div><div>&nbsp;</div><div>&nbsp;</div><div>Regards,</div><div>&nbsp;&nbsp; Silvio.</div><span style="font-size:10px"><br /><br />Edited by sbelini - 31-Aug-2011 at 10:40am</span>]]>
   </description>
   <pubDate>Wed, 31 Aug 2011 10:39:19 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2929&amp;PID=11607#11607</guid>
  </item> 
  <item>
   <title>Null Entity Incorrectly Attached :   Hi Ian,Thanks for the clarification.I&amp;#039;ll...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2929&amp;PID=11606#11606</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=892" rel="nofollow">sbelini</a><br /><strong>Subject:</strong> 2929<br /><strong>Posted:</strong> 31-Aug-2011 at 7:44am<br /><br />Hi Ian,<div>&nbsp;</div><div>Thanks for the clarification.</div><div>&nbsp;</div><div>I'll try to repro it here and let you know. </div><div>&nbsp;</div><div>Silvio.</div>]]>
   </description>
   <pubDate>Wed, 31 Aug 2011 07:44:12 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2929&amp;PID=11606#11606</guid>
  </item> 
  <item>
   <title>Null Entity Incorrectly Attached :   Hi Silvio, Thanks for the...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2929&amp;PID=11605#11605</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=530" rel="nofollow">Didsbo</a><br /><strong>Subject:</strong> 2929<br /><strong>Posted:</strong> 31-Aug-2011 at 4:57am<br /><br />Hi Silvio,<div> </div><div>Thanks for the reply.  I'll create a sample using Northwind as requested however in the meantime the following information relating to my model might be useful.</div><div> </div><div>I have an entity call Asset that has a 1 to many association with an entity call SystemItem.  The SystemItem entity has a recursive (0..1 to many) associated  (Parent/ Children).</div><div> </div><div>If I create a SystemItem as follows I can reproduce the behaviour in my Siverlight application but not in my WPF application (identical model):</div><div> </div><div><font size="2"><font face="C&#111;nsolas"><font color="#0000ff">  &nbsp; var</font> mgr = <font color="#0000ff"><font color="#0000ff"><font color="#0000ff">new</font></font></font> <font color="#2b91af"><font color="#2b91af"><font color="#2b91af">MyEntities</font></font></font>();</font></font></div><div><font size="2"><font face="C&#111;nsolas"><font color="#0000ff">  &nbsp; var</font> systemItem= <font color="#0000ff"><font color="#0000ff"><font color="#0000ff">new</font></font></font> <font color="#2b91af"><font color="#2b91af"><font color="#2b91af">SystemItem</font></font></font>();</font></font></div><div><font size="2" face="C&#111;nsolas">  &nbsp; systemItem.Id = Guid.NewGuid()</font></div><div><font size="2"><font face="C&#111;nsolas"><font color="#0000ff">  &nbsp; var</font> assetEntityState = systemItem.Asset.EntityAspect.EntityState; <font color="#008000"><font color="#008000"><font color="#008000">// <font color="#000000">assetEntityState</font> is Detached</font></font></font></font></font></div><div><font size="2"><font face="C&#111;nsolas"><font color="#0000ff">  &nbsp; var</font> isNullAsset = systemItem.Asset.EntityAspect.IsNullEntity; <font color="#008000"><font color="#008000"><font color="#008000">// isNullCustomer is false</font></font></font></font></font></div><div><font size="2"><font face="C&#111;nsolas"><font color="#0000ff">  &nbsp; var</font> parentEntityState = systemItem.Parent.EntityAspect.EntityState; <font color="#008000"><font color="#008000"><font color="#008000">// <font color="#000000">assetEntityState</font> is Detached</font></font></font></font></font></div><div><font size="2"><font face="C&#111;nsolas"><font color="#0000ff">  &nbsp; var</font> isNullParent = systemItem.Parent.EntityAspect.IsNullEntity; <font color="#008000"><font color="#008000"><font color="#008000">// isNullCustomer is false</font></font></font></font></font></div><div><font size="2"><font face="C&#111;nsolas">  &nbsp; mgr.AddEntity(systemItem);</font></font></div><div><font size="2" face="C&#111;nsolas">  &nbsp; <font color="#0000ff">var</font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas"> assetEntityState = systemItem.Asset.EntityAspect.EntityState; </font></font><font color="#008000" size="2" face="C&#111;nsolas"><font color="#008000" size="2" face="C&#111;nsolas"><font color="#008000" size="2" face="C&#111;nsolas">// <font color="#000000">assetEntityState</font> is Attached</font></font></font></font></div><div><font size="2"><font face="C&#111;nsolas"><font color="#0000ff">  &nbsp; var</font> isNullAsset = systemItem.Asset.EntityAspect.IsNullEntity; <font color="#008000"><font color="#008000"><font color="#008000">// isNullCustomer is True</font></font></font></font></font></div><div><font size="2"><font face="C&#111;nsolas"><font color="#0000ff">  &nbsp; var</font> parentEntityState = systemItem.Parent.EntityAspect.EntityState; <font color="#008000"><font color="#008000"><font color="#008000">// <font color="#000000">assetEntityState</font> is Detached</font></font></font></font></font></div><div><font size="2"><font face="C&#111;nsolas"><font color="#0000ff">  &nbsp; var</font> isNullParent = systemItem.Parent.EntityAspect.IsNullEntity; <font color="#008000"><font color="#008000"><font color="#008000">// isNullCustomer is false</font></font></font></font></font></div><div><font size="2" face="C&#111;nsolas"></font> </div><div><font size="2" face="C&#111;nsolas">I have resolved this issue by quering mgr.Assets (local cache only) before creating a SystemItem.  In fact, I don't have to query Assets as any query against the EntityManager will resolve the issue.  It seems this issue might be related to the initialisation of the EntityManager.  This issue effects all entities in model, not just Assets and SystemItems, where the multiplicity is 1.</font></div><div><font size="2" face="C&#111;nsolas"></font> </div><div><font size="2" face="C&#111;nsolas">If you can't reproduce using NorthwindIB then the problem must be with my model.  I can't think where the problem might be.  Any ideas?</font></div><div><font size="2" face="C&#111;nsolas"></font> </div><div><font size="2" face="C&#111;nsolas">I thought it might be related by my SystemItem buddy class / metadata - a have a NullValueVerifier attribute on the Asset property.  I removed this but still had the issue.</font></div><div><font size="2" face="C&#111;nsolas"></font> </div><div><font size="2" face="C&#111;nsolas">Regards</font></div><div><font size="2" face="C&#111;nsolas"></font> </div><div><font size="2" face="C&#111;nsolas">Ian</font></div>]]>
   </description>
   <pubDate>Wed, 31 Aug 2011 04:57:58 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2929&amp;PID=11605#11605</guid>
  </item> 
  <item>
   <title>Null Entity Incorrectly Attached :   Hi Didsbo,I was not able to...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2929&amp;PID=11563#11563</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=892" rel="nofollow">sbelini</a><br /><strong>Subject:</strong> 2929<br /><strong>Posted:</strong> 29-Aug-2011 at 11:28am<br /><br />Hi Didsbo,<div>&nbsp;</div><div>I was not able to reproduce the behavior you described.</div><div>&nbsp;</div><div><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas">&nbsp; var</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas"> mgr = </font></font><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas">new</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas"> </font></font><font color="#2b91af" size="2" face="C&#111;nsolas"><font color="#2b91af" size="2" face="C&#111;nsolas"><font color="#2b91af" size="2" face="C&#111;nsolas">NorthwindIBEntities</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas">();</font></font></div><div><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas">&nbsp; var</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas"> order = </font></font><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas">new</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas"> </font></font><font color="#2b91af" size="2" face="C&#111;nsolas"><font color="#2b91af" size="2" face="C&#111;nsolas"><font color="#2b91af" size="2" face="C&#111;nsolas">Order</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas">();</font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas">mgr.AddEntity(order);</font></font></div><div><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas">&nbsp; var</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas"> customerEntityState = order.Customer.EntityAspect.EntityState; </font></font><font color="#008000" size="2" face="C&#111;nsolas"><font color="#008000" size="2" face="C&#111;nsolas"><font color="#008000" size="2" face="C&#111;nsolas">// customerEntityState is Detached</font></font></font></div><div><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas"><font color="#0000ff" size="2" face="C&#111;nsolas">&nbsp; var</font></font></font><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas"> isNullCustomer = order.Customer.EntityAspect.IsNullEntity; </font></font><font color="#008000" size="2" face="C&#111;nsolas"><font color="#008000" size="2" face="C&#111;nsolas"><font color="#008000" size="2" face="C&#111;nsolas">// isNullCustomer is true</font></font></font></div><div>&nbsp;</div><div>Can you provide a sample reproducing the issue? (against NorthwindIB, please)</div><div>&nbsp;</div><div>Regards,</div><div>&nbsp;&nbsp; Silvio.</div>]]>
   </description>
   <pubDate>Mon, 29 Aug 2011 11:28:56 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2929&amp;PID=11563#11563</guid>
  </item> 
  <item>
   <title>Null Entity Incorrectly Attached :   Interestingly, if I query...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2929&amp;PID=11542#11542</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=530" rel="nofollow">Didsbo</a><br /><strong>Subject:</strong> 2929<br /><strong>Posted:</strong> 26-Aug-2011 at 2:08am<br /><br />Interestingly, if I query EntityManager.Customers before I create and add an order then the customer null entity is correctly not added to the entitymanager.&nbsp; Wierd.]]>
   </description>
   <pubDate>Fri, 26 Aug 2011 02:08:03 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2929&amp;PID=11542#11542</guid>
  </item> 
  <item>
   <title>Null Entity Incorrectly Attached :   Hi, I&amp;#039;m experiencing...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2929&amp;PID=11541#11541</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=530" rel="nofollow">Didsbo</a><br /><strong>Subject:</strong> 2929<br /><strong>Posted:</strong> 26-Aug-2011 at 1:53am<br /><br />Hi,<div> </div><div>I'm experiencing unexpected behaviour in my silverlight application.  When I add an entity of type Order to the entity manager using EntityManager.AddEntity(order), an entity is also added to the entity manager for the Customer navigation property (order.Customer).  The customer entity is effectively a null entity (Id is an empty Guid) however customer.EntityAspect.IsNullEntity is false.  The customer null entity should not be added to the manager and should remain detached.</div><div> </div><div>In my WPF application, using the the same entitymodel, the customer null entity is correctly never added to the entitymanager and remains detached when I add an order.  </div><div> </div><div>Is this behaviour for Silverlight expected?  Why is it different to the WPF behaviour?  What can I do to prevent null entities being added to the EntityManager?</div><div> </div><div>Thanks</div><div> </div><div>Ian</div>]]>
   </description>
   <pubDate>Fri, 26 Aug 2011 01:53:10 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2929&amp;PID=11541#11541</guid>
  </item> 
 </channel>
</rss>