<?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 saving list of related objects</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Error saving list of related objects</description>
  <pubDate>Sat, 11 Apr 2026 21:16:12 -700</pubDate>
  <lastBuildDate>Sun, 10 Oct 2010 03:37:22 -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=2170</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 saving list of related objects : I figured out the problem. I was...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2170&amp;PID=8757#8757</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=870" rel="nofollow">hueha</a><br /><strong>Subject:</strong> 2170<br /><strong>Posted:</strong> 10-Oct-2010 at 3:37am<br /><br />I figured out the problem. &nbsp;I was using the entityaspect delete on the contact (one side of the many to many) and removing it from the contact list in the locaton (the other side of the many to many). &nbsp;When I removed the location from the locations list in contact before deleting it then it worked]]>
   </description>
   <pubDate>Sun, 10 Oct 2010 03:37:22 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2170&amp;PID=8757#8757</guid>
  </item> 
  <item>
   <title>Error saving list of related objects : As in I created and saved the...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2170&amp;PID=8746#8746</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=870" rel="nofollow">hueha</a><br /><strong>Subject:</strong> 2170<br /><strong>Posted:</strong> 07-Oct-2010 at 3:31pm<br /><br />As in I created and saved the objects to the database in this session.&nbsp; If I quit my application after saving and then try to delete it seems to work. &nbsp;&nbsp; I will try and make a sample app but it may take a few days]]>
   </description>
   <pubDate>Thu, 07 Oct 2010 15:31:56 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2170&amp;PID=8746#8746</guid>
  </item> 
  <item>
   <title>Error saving list of related objects : hueha,   The error &amp;#034;The...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2170&amp;PID=8743#8743</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> 2170<br /><strong>Posted:</strong> 07-Oct-2010 at 12:11pm<br /><br />hueha, <DIV>&nbsp;</DIV><DIV>The error "The DELETE statement conflicted with the REFERENCE constraint..." comes from the SQL server, so you are most likely violating a reference constraint.</DIV><DIV>&nbsp;</DIV><DIV>As for it only happening with elements that have just been created, I could not reproduce it here.</DIV><DIV>&nbsp;</DIV><DIV>When you mention just created, do you mean not saved into the datasource yet? (i.e. existing only in the cache)</DIV><DIV>If the just created entities were actually saved into the datasource, does the issue persists on subsequent executions? (i.e.&nbsp;on the subsequent executions these entities would be "loaded from the db" and not "just created" anymore)</DIV><DIV>&nbsp;</DIV><DIV>Can you upload a simple test case reproducing the issue above stated, so I can further investigate the issue?</DIV>]]>
   </description>
   <pubDate>Thu, 07 Oct 2010 12:11:37 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2170&amp;PID=8743#8743</guid>
  </item> 
  <item>
   <title>Error saving list of related objects : I get the following error when...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2170&amp;PID=8559#8559</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=870" rel="nofollow">hueha</a><br /><strong>Subject:</strong> 2170<br /><strong>Posted:</strong> 18-Sep-2010 at 8:43am<br /><br />I get the following error when trying to save (using devforce 6.0.5)<div><br><div>Entity Save Error: System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---&gt; System.Data.SqlClient.SqlException: The DELETE statement conflicted with the REFERENCE constraint "FK_CompanyLocation_Company". The conflict occurred in database "jts2", table "dbo.CompanyLocation", column 'CompanyID'. The statement has been terminated. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues) at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter) --- End of inner exception stack trace --- at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter) at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache) at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options) at IdeaBlade.EntityModel.Edm.EdmSaveExecutor.ProcessSaves(IEnumerable`1 groupsByType) at IdeaBlade.EntityModel.Edm.EdmSaveExecutor.SaveWithinContext() at IdeaBlade.EntityModel.Edm.EdmSaveExecutor.Save(DataSourceResolver dataSourceResolver, IDataSourceKey dsKey, SaveWorkState workState)</div><div><br></div><div>What I'm doing is trying to delete a company using an entitygraph</div><div><br></div><div><div>&nbsp;public List&lt;EntitySpan&gt; GetSpan()</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; List&lt;EntitySpan&gt; spans = new List&lt;EntitySpan&gt;();</div><div><br></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;EntitySpan aSpan =&nbsp;new EntitySpan(typeof(Company), EntityRelations.FK_CompanyLocation_Company);</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;spans.Add(aSpan);</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aSpan = new EntitySpan(typeof(Company), EntityRelations.FK_CompanyContact_Company);</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;spans.Add(aSpan);</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return spans;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div><br></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;public void GetEntityGraphAsync(Action&lt;IList&lt;Object&gt;&gt; callback)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //First ensure all children are loaded</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IEntityQuery&lt;Company&gt; query =((JTS2Entities) this.EntityAspect.EntityManager).Companies.Where(c =&gt; c.CompanyID == this.CompanyID)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.Include(EntityPropertyNames.CompanyContacts)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.Include(EntityPropertyNames.CompanyLocations);</div><div><br></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;((JTS2Entities)this.EntityAspect.EntityManager).ExecuteQueryAsync&lt;Company&gt;(query</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;, (o) =&gt; {</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Create roots list and add the employee.</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;List&lt;Entity&gt; roots = new List&lt;Entity&gt;();</div><div><br></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;roots.Add(this);</div><div><br></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Add span(s).</div><div><br></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;List&lt;EntitySpan&gt; spans = GetSpan();</div><div><br></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Get entity graph for entities in roots</div><div><br></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;EntityState entityState = EntityState.AllButDetached;</div><div><br></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IList&lt;Object&gt; entityGraph = this.EntityAspect.EntityManager.FindEntityGraph(roots, spans, entityState);</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;callback(entityGraph);</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;, null);</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div></div><div><br></div><div>after getting the entityGraph i iterate over it and delete them</div><div><br></div><div><div><span ="Apple-tab-span" style="white-space:pre">	</span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;foreach (var item in entityGraph)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ((Entity)item).EntityAspect.Delete();</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div></div><div><br></div><div>then I call save</div><div><span ="Apple-tab-span" style="white-space:pre">	</span></div><div><span ="Apple-tab-span" style="white-space:pre">		 _mgr.SaveChangesAsync(</span>entityGraph<span ="Apple-tab-span" style="white-space:pre">, null, SaveCallBack, null);</span></div><div><span ="Apple-tab-span" style="white-space:pre"><br></span></div><div><span ="Apple-tab-span" style="white-space:pre">W</span>hat I think is happening is that it is deleting them in the wrong order. &nbsp;It's trying to delete the company first before the location. &nbsp;Possibly by deleting the location I have confused the framework that there are no relations?</div><div><br></div><div>Also, this only happens if I just created the company and location. &nbsp;If the company (and its locations and contacts) was just loaded from the database the delete seems to work.</div><div><br></div><div><br></div></div>]]>
   </description>
   <pubDate>Sat, 18 Sep 2010 08:43:52 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2170&amp;PID=8559#8559</guid>
  </item> 
 </channel>
</rss>