<?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 : Deleting entities</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Deleting entities</description>
  <pubDate>Thu, 11 Jun 2026 17:12:57 -700</pubDate>
  <lastBuildDate>Wed, 05 Jan 2011 18:34:30 -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=2419</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>Deleting entities : Hi sky40627,  I was not able...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2419&amp;PID=9571#9571</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> 2419<br /><strong>Posted:</strong> 05-Jan-2011 at 6:34pm<br /><br />Hi sky40627,<DIV>&nbsp;</DIV><DIV>I was not able to reproduce the issue here.</DIV><DIV>Here is my test case:</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>&#091;</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>TestMethod</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>&#093;</DIV><DIV><DIV></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>public</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas> </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>void</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas> TestDelete() {</DIV><DIV></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>&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>IdeaBladeTest1Entities</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>();</DIV><DIV></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></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>&nbsp; </FONT></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>var</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas> empToDelete = mgr.Employees.First();</DIV><DIV></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>&nbsp; var</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas> id = empToDelete.Id;</DIV><DIV>&nbsp; empToDelete.EntityAspect.Delete();</DIV><DIV>&nbsp; mgr.SaveChanges(); <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>// Persisting the delete</FONT></FONT></FONT></DIV><DIV><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>&nbsp;</DIV><DIV></FONT></FONT></FONT></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>&nbsp; var</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas> newEmp = mgr.CreateEntity&lt;</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>&gt;();</DIV><DIV>&nbsp; newEmp.Id = id;</DIV><DIV>&nbsp; newEmp.FirstName = </FONT></FONT><FONT color=#a31515 size=2 face=C&#111;nsolas><FONT color=#a31515 size=2 face=C&#111;nsolas><FONT color=#a31515 size=2 face=C&#111;nsolas>"Joe"</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>DateTime</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>.Now.Ticks.ToString();</DIV><DIV>&nbsp; newEmp.LastName = </FONT></FONT><FONT color=#a31515 size=2 face=C&#111;nsolas><FONT color=#a31515 size=2 face=C&#111;nsolas><FONT color=#a31515 size=2 face=C&#111;nsolas>"Doe"</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>;</DIV><DIV>&nbsp; mgr.AddEntity(newEmp);</DIV><DIV>&nbsp; mgr.SaveChanges(); <FONT color=#008000>// Storing the new employee</FONT></DIV><DIV>}</DIV><DIV></FONT></FONT>&nbsp;</DIV><DIV>However, if&nbsp;you comment out the first <strong>mgr.SaveChanges()</strong> in the code then you will get the exception you described. </DIV><DIV>In That case, it happens because even though you have deleted the entity, you have not yet persisted the changes by calling <strong>mgr.SaveChanges</strong>.</DIV><DIV>&nbsp;</DIV><DIV>Can you please provide a solution reproducing the issue?</DIV><DIV>&nbsp;</DIV><DIV>On a second note, why are you trying to recycle PKs? Ideally, a primary key should be unique to&nbsp;one entity (regardless of if the entity has been deleted)</DIV></DIV>]]>
   </description>
   <pubDate>Wed, 05 Jan 2011 18:34:30 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2419&amp;PID=9571#9571</guid>
  </item> 
  <item>
   <title>Deleting entities : Hi,  I am trying to do the following  var...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2419&amp;PID=9559#9559</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=595" rel="nofollow">sky40627</a><br /><strong>Subject:</strong> 2419<br /><strong>Posted:</strong> 05-Jan-2011 at 4:34am<br /><br />Hi,<DIV>&nbsp;</DIV><DIV>I am trying to do the following</DIV><DIV>&nbsp;</DIV><DIV><strong>var q = _manager.UnpaidInvoices;<BR>foreach (var unpaidInvoice in q)<BR>&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unpaidInvoice.EntityAspect.Delete();<BR>&nbsp; }<BR>_manager.SaveChanges();</strong></DIV><DIV><strong></strong>&nbsp;</DIV><DIV>when looking in the database the entities are deleted</DIV><DIV>&nbsp;</DIV><DIV>but somehow they are still present in the entitymanager</DIV><DIV>&nbsp;</DIV><DIV>because when i start adding the new entities i get an error saying that an entity with this key already exists.</DIV><DIV><DIV><strong></strong>&nbsp;</DIV><DIV><strong>foreach (var item in list)</strong></DIV><DIV><strong>{</strong></DIV><DIV><strong>&nbsp;&nbsp; UnpaidInvoice ui = UnpaidInvoice.Create(_manager, item.Id);</strong></DIV><DIV><strong>}</strong></DIV><DIV><strong>_manager.SaveChanges();</strong></DIV><DIV><strong></strong>&nbsp;</DIV></DIV><DIV>also is it necessary to do the savechanges after the&nbsp;delete of the entities ?</DIV><DIV>&nbsp;</DIV><DIV>here under is the create method</DIV><DIV>&nbsp;</DIV><DIV><strong>public static UnpaidInvoice Create(EntityManager pEntityManager, string pId)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UnpaidInvoice upi = pEntityManager.CreateEntity&lt;UnpaidInvoice&gt;();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; upi.Id = pId;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;upi.EntityAspect.AddToManager();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return upi;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</strong></DIV><DIV><strong></strong>&nbsp;</DIV><DIV>what am I doing wrong here? Why isn't the cache update after the delete ?</DIV>]]>
   </description>
   <pubDate>Wed, 05 Jan 2011 04:34:07 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2419&amp;PID=9559#9559</guid>
  </item> 
 </channel>
</rss>