<?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 : Error adding to manager</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Error adding to manager</description>
  <pubDate>Wed, 13 May 2026 18:17:57 -700</pubDate>
  <lastBuildDate>Mon, 14 Nov 2011 14:34:44 -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=3093</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>Error adding to manager :  I have found what is causing...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3093&amp;PID=12056#12056</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> 3093<br /><strong>Posted:</strong> 14-Nov-2011 at 2:34pm<br /><br />I have found what is causing it.<br><br>In my ViewModel I have a collection changed event listening for UserProducts to change. This event is fired before the product has been set on UserProduct.&nbsp; When I comment the collection changed code, it works flawlessly.<br><br>When this collection changes I have the following code:<br><br><pre style="font-family:C&#111;nsolas;font-size:13;color:black;:white;">&nbsp;&nbsp;&nbsp;<span style="color:blue;">private</span>&nbsp;<span style="color:blue;">void</span>&nbsp;UserProductsChanged(<span style="color:blue;">object</span>&nbsp;sender,&nbsp;<span style="color:#2b91af;">NotifyCollectionChangedEventArgs</span>&nbsp;e)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;          NotifyOfPropertyChange(()&nbsp;=&gt;&nbsp;UserProducts);<br>        }<br></pre><br><pre style="font-family:C&#111;nsolas;font-size:13;color:black;:white;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">public</span>&nbsp;<span style="color:#2b91af;">IEnumerable</span>&lt;<span style="color:#2b91af;">Product</span>&gt;&nbsp;UserProducts&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">get</span>&nbsp;{&nbsp;<span style="color:blue;">return</span>&nbsp;User.UserProducts.Select(up&nbsp;=&gt;&nbsp;up.Product);&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</pre><br><br>This appears to be the solution:<br><br><pre style="font-family:C&#111;nsolas;font-size:13;color:black;:white;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">public</span>&nbsp;<span style="color:blue;">void</span>&nbsp;AddProduct(<span style="color:#2b91af;">Product</span>&nbsp;product)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">var</span>&nbsp;userProduct&nbsp;=&nbsp;<span style="color:blue;">new</span>&nbsp;<span style="color:#2b91af;">UserProduct</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ProductId&nbsp;=&nbsp;product.ProductId&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EntityAspect.EntityManager.AddEntity(userProduct); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userProduct.UserId&nbsp;=&nbsp;UserId;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>This way the product is getting resolved before I attach it to the user (Which fires off the collection event)<br><br><br></pre><br><span style="font-size:10px"><br /><br />Edited by smi-mark - 14-Nov-2011 at 2:37pm</span>]]>
   </description>
   <pubDate>Mon, 14 Nov 2011 14:34:44 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3093&amp;PID=12056#12056</guid>
  </item> 
  <item>
   <title>Error adding to manager :  I&amp;#039;m getting the following...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3093&amp;PID=12055#12055</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> 3093<br /><strong>Posted:</strong> 14-Nov-2011 at 2:24pm<br /><br />I'm getting the following error while trying to add an entity to the manager:<br><br>Null or pending entities cannot be modified<br><br>This is the layout of the data:<br><br><b>User</b><br>&nbsp; UserId<br><br><b>UserProduct</b><br>&nbsp; UserProductId<br>&nbsp; UserId<br>&nbsp; ProductId<br><br><b>Product</b><br>&nbsp; ProductId<br><br>This is the code I am using that fails:<br><br><pre style="font-family:C&#111;nsolas;font-size:13;color:black;:white;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">public</span>&nbsp;<span style="color:blue;">void</span>&nbsp;AddProduct(<span style="color:#2b91af;">Product</span>&nbsp;product)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">var</span>&nbsp;userProduct&nbsp;=&nbsp;<span style="color:blue;">new</span>&nbsp;<span style="color:#2b91af;">UserProduct</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UserId&nbsp;=&nbsp;UserId,<br>                                      ProductId = product.ProductId&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EntityAspect.EntityManager.AddEntity(userProduct);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>I have tried it with or without setting ProductId = product.ProductId<br><br>User.EntityAspect.IsNullOrPendingEntity = false<br>User.UserProducts IsPendingEntityList = false<br><br>What is very interesting is, sometimes if I set breakpoint on the AddEntity line, wait a few seconds, then let it execute, it works.<br><br>The detached entity is trying to resolve something and it is failing initially.<br><br>This is the stacktrace:<br><br>   at IdeaBlade.EntityModel.EntityAspect.SetValueWithChangeNotification(DataEntityProperty property, Object newValue)<br>   at IdeaBlade.EntityModel.EntityManager.GenerateId(Object entity, DataEntityProperty entityProperty)<br>   at IdeaBlade.EntityModel.EntityManager.UpdatePkIfNeeded(EntityAspect aspect)<br>   at IdeaBlade.EntityModel.EntityManager.AttachEntityAspect(EntityAspect aspect, EntityState entityState)<br>   at IdeaBlade.EntityModel.EntityManager.&lt;&gt;c__DisplayClass60.&lt;AddOrAttachRelatedEntities&gt;b__5d(EntityAspect w)<br>   at IdeaBlade.Core.EnumerableFns.ForEach&#091;T&#093;(IEnumerable`1 items, Action`1 action)<br>   at IdeaBlade.EntityModel.EntityManager.AddOrAttachRelatedEntities(EntityAspect wrapper, EntityState entityState)<br>   at IdeaBlade.EntityModel.EntityManager.AttachEntityAspect(EntityAspect aspect, EntityState entityState)<br>   at IdeaBlade.EntityModel.EntityManager.AttachEntity(Object entity, EntityState entityState)<br>   at IdeaBlade.EntityModel.EntityManager.AddEntity(Object entity)<br>   at Spindlemedia.Models.Security.User.AddProduct(Product product)<br><br>At the time of the exception:<br><br>UserProduct is successfully added to the manager, with a generated id of -100 and it is in the Added State<br><br>UserProduct.Product.EntityAspect.IsNullOrPendingEntity = <b>true</b><br>UserProduct.User.EntityAspect.IsNullOrPendingEntity = false<br><br>They are both in the same entity manager, so I'm not sure what the issue is.<br><br>Thoughts?<br></pre><br><span style="font-size:10px"><br /><br />Edited by smi-mark - 14-Nov-2011 at 2:27pm</span>]]>
   </description>
   <pubDate>Mon, 14 Nov 2011 14:24:28 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3093&amp;PID=12055#12055</guid>
  </item> 
 </channel>
</rss>