<?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 : Table Splitting</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Table Splitting</description>
  <pubDate>Tue, 12 May 2026 23:20:14 -700</pubDate>
  <lastBuildDate>Fri, 04 Jan 2013 11:09: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=3487</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>Table Splitting : Sorry for the delay. Been sidetracked...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=15507#15507</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=613" rel="nofollow">stephenmcd1</a><br /><strong>Subject:</strong> 3487<br /><strong>Posted:</strong> 04-Jan-2013 at 11:09am<br /><br /><p>Sorry for the delay. &nbsp;Been sidetracked by other projects.</p><p>In our case, we do have the LoadStrategy set to DoNotLoad. &nbsp;Perhaps that's why we couldn't go the easy way. &nbsp;Although, the reason that I'm using table splitting in this case is because the 'other half' of this entity is a large binary field - which could be many megabytes if not larger. &nbsp;I'd really rather not have to query for it just to delete it. &nbsp;</p><p>Having to query for the 'other half' of the item in order to delete it isn't really the end of the world. &nbsp;However, I was mainly giving that example in response to your request of "As for the second issue, could you provide a use case where setting Navigation Properties on a Deleted Entity would be necessary. (i.e. necessary in the sense that you'd need to manipulate Deleted entities)". &nbsp;This case was one place where we'd like to be able to use navigation properties on deleted items. &nbsp;Sure, if we weren't using DoNotLoad LoadStrategy (which we can't really change at this point), it would get around this case - but it seems like a valid way to code. &nbsp;Then the code I gave in the subsequent <a href="http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=15342&amp;title=table-splitting#15342" target="_blank">post</a> was an even more basic case where I'd want/expect navigation properties to work for deleted items.</p><p>Hope that makes sense.</p><p><br></p>]]>
   </description>
   <pubDate>Fri, 04 Jan 2013 11:09:44 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=15507#15507</guid>
  </item> 
  <item>
   <title>Table Splitting : Stephen,  Sorry if my response...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=15344#15344</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> 3487<br /><strong>Posted:</strong> 05-Dec-2012 at 12:05pm<br /><br />Stephen,<br /><br />Sorry if my response wasn't clear.<br />What I meant to say is that you don't need to create a dummy entity and delete it to satisfy EF. The check <br /><br /><em>customer.CustomerAddress == null</em> <br /><br />isn't necessary either.<br /><br />You should be able to simply call<br /><br /><em>customer.ContactAddress.EntityAspect.Delete() </em><br /><br />i.e. assuming you did not set LoadStrategy to DoNotLoad. Otherwise, you'd have to query the for the ContactAddress first.<br /><br />sbelini.]]>
   </description>
   <pubDate>Wed, 05 Dec 2012 12:05:45 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=15344#15344</guid>
  </item> 
  <item>
   <title>Table Splitting : The delete line is not what is...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=15342#15342</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=613" rel="nofollow">stephenmcd1</a><br /><strong>Subject:</strong> 3487<br /><strong>Posted:</strong> 05-Dec-2012 at 11:19am<br /><br />The delete line is not what is causing problems. &nbsp;It's the navigation properties. &nbsp;Below is some code that maybe explains it better than I can in English.<div><br></div><div>Note: In my case, I have the&nbsp;principle/dependent roles swapped I think - because of the other issues in this thread. &nbsp;But I don't think that changes the fact that there are problems with navigation properties.<table width="99%"><tr><td><pre class="BBcode">&nbsp; &nbsp; &nbsp; &nbsp;&#091;TestMethod&#093;</div><div><div>&nbsp; &nbsp; &nbsp; &nbsp; public void TestDeletedEntityNavigations()</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var em = new EntityManager();</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Make the Customer and CustomerAddress - hard-coding the same key</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var customer = new Customer {CustomerID = 123};</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var customerAddress = new CustomerAddress {CustomerID = 123};</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Add both entities to the entity manager</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; em.AttachEntities(new Entity&#091;&#093; {customer, customerAddress});</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Since they have the same PK, DevForce automatically updated the navigation properties so</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp;these two tests will pass.</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assert.AreEqual(customer, customerAddress.Customer, "customerAddress.Customer is wrong");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assert.AreEqual(customerAddress, customer.CustomerAddress, "customer.CustomerAddress is wrong");</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Now delete the two entities (in practice, we only need to delete the customer and that will</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp;cascade to the CustomerAddress as well - but we'll be explicit here for demonstration purposes)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; customer.EntityAspect.Delete();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; customerAddress.EntityAspect.Delete();</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //I'd still expect (and want) the navigation properties to still work. &nbsp;This first check will work...</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assert.AreEqual(customer, customerAddress.Customer, "customerAddress.Customer is wrong");</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //But then this one will fail. &nbsp;customer.CustomerAddress is pointing to a NullEntity</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assert.AreEqual(customerAddress, customer.CustomerAddress, "customer.CustomerAddress is wrong");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</pre></td></tr></table></div></div>]]>
   </description>
   <pubDate>Wed, 05 Dec 2012 11:19:18 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=15342#15342</guid>
  </item> 
  <item>
   <title>Table Splitting : Hi Stephen  In DevForce 2010...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=15333#15333</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> 3487<br /><strong>Posted:</strong> 04-Dec-2012 at 5:05pm<br /><br /><DIV>Hi Stephen</DIV><DIV>&nbsp;</DIV><DIV>In DevForce 2010 v.6.1.10.0 you should be able to do:</DIV><DIV>&nbsp;</DIV><DIV><EM>&nbsp;customer.ContactAddress.EntityAspect.Delete() </EM></DIV><DIV>&nbsp;</DIV><DIV>in your SaveInterceptor pre-save logic. </DIV><DIV>&nbsp;</DIV><DIV>sbelini.</DIV>]]>
   </description>
   <pubDate>Tue, 04 Dec 2012 17:05:01 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=15333#15333</guid>
  </item> 
  <item>
   <title>Table Splitting : The big use case where I want...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=15332#15332</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=613" rel="nofollow">stephenmcd1</a><br /><strong>Subject:</strong> 3487<br /><strong>Posted:</strong> 04-Dec-2012 at 10:46am<br /><br />The big use case where I want to be able to use navigation properties for deleted items is when I'm deleting entities that are using table&nbsp;splitting&nbsp;(as in this case). &nbsp;I'll use the example I gave in the first post - a Custom entity that is the 'main' entity and then CustomAddress that is basically optional data that I don't usually want to bring down to the client. &nbsp;If I do simple code like this, it won't work:<div><table width="99%"><tr><td><pre class="BBcode">entityManager.Customers.Single(c =&gt; c.CustomID == someId).EntitAspect.Delete();</div><div>entityManager.SaveChanges();</pre></td></tr></table></div><div>EF will complain that "Invalid data encountered. A required relationship is missing". &nbsp;It seems EF needs the Customer and CustomerAddress entities to be be loaded and both marked as deleted. &nbsp;I already have a bunch of pre-save logic in a custom EntityServerSaveInterceptor so I use that place to automatically fix this problem. &nbsp;It goes something like this:</div><div><table width="99%"><tr><td><pre class="BBcode">//Loop through any deleted Customer entities to fix them up</div><div>foreach(var customer in EntityManager.FindEntities&lt;Customer&gt;(EntityState.Deleted)</div><div>{</div><div>&nbsp; &nbsp;//If the CustomerAddress wasn't loaded, we need to make a placeholder one to make EF happy</div><div>&nbsp; &nbsp;if(customer.CustomerAddress == null)</div><div>&nbsp; &nbsp;{</div><div>&nbsp; &nbsp; &nbsp; &nbsp;//Make the placeholder and assign it to the navigation property.</div><div>&nbsp; &nbsp; &nbsp; &nbsp;customer.CustomerAddress = EntityManager.CreateEntity&lt;CustomerAddress&gt;()</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp;//Before deleting this entity, we need to accept the changes...otherwise it will become detached</div><div>&nbsp; &nbsp; &nbsp; &nbsp;customer.CustomerAddres.EntityAspect.AcceptChanges();</div><div>&nbsp; &nbsp; &nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;//Now delete it</div><div>&nbsp; &nbsp; &nbsp; &nbsp;customer.CustomerAddress.EntityAspect.Delete();</div><div>&nbsp; &nbsp; }</div><div>}</pre></td></tr></table></div><div>In principle, that code should work but the navigation issue with deleted entities ends up causing problems. &nbsp;For example, when I go to check if the CustomerAddress navigation property is filled in, it will never show up....even when the CustomerAddress entity is in the entity manager. &nbsp;So I have to search the entity manager cache manually which isn't terribly hard but is awkward (and makes it hard to do this kind of logic generically). &nbsp;Then also, when I assign the placeholder CustomerAddress to the navigation property, the CustomerAddress doesn't get its Primary Key fields updated with those on the customer - so then EF still complains because all it sees is a CustomerAddress with Primary Key of zero - which doesn't match the Customer.</div><div><br></div><div>There are other places in our code where it would be nice for navigation properties to work even for deleted entities. &nbsp;There are other entities that do logic as they are about to be saved in the EntityServerSaveInterceptor and it is annoying that we can't just 'dot' around the properties to see if other things are loaded.</div>]]>
   </description>
   <pubDate>Tue, 04 Dec 2012 10:46:03 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=15332#15332</guid>
  </item> 
  <item>
   <title>Table Splitting : Stephen,  The first issue (Referential...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=15325#15325</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> 3487<br /><strong>Posted:</strong> 03-Dec-2012 at 5:11pm<br /><br />Stephen,<br /><br />The first issue (Referential Constraint seems to be reversed) has been fixed and the fix will be in DevForce v6.1.10.0.<br /><br />As for the second issue, could you provide a use case where setting Navigation Properties on a Deleted Entity would be necessary. (i.e. necessary in the sense that you'd need to manipulate Deleted entities)<br /><br />Regards,<br />&nbsp;&nbsp;&nbsp;sbelini.]]>
   </description>
   <pubDate>Mon, 03 Dec 2012 17:11:24 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=15325#15325</guid>
  </item> 
  <item>
   <title>Table Splitting : Hi Stephen,  Unfortunatelly, these...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=15295#15295</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> 3487<br /><strong>Posted:</strong> 29-Nov-2012 at 8:39am<br /><br />Hi Stephen,<br /><br />Unfortunatelly, these bugs have not been fixed yet.<br /><br />I am bringing them up again to our engineers and will try to push them up in the priority list.<br /><br />sbelini.]]>
   </description>
   <pubDate>Thu, 29 Nov 2012 08:39:47 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=15295#15295</guid>
  </item> 
  <item>
   <title>Table Splitting : Have any of these bugs been fixed...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=15287#15287</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=613" rel="nofollow">stephenmcd1</a><br /><strong>Subject:</strong> 3487<br /><strong>Posted:</strong> 27-Nov-2012 at 3:14pm<br /><br />Have any of these bugs been fixed yet? &nbsp;We recently upgraded to 6.1.9.0 but the problems still seem to be there.]]>
   </description>
   <pubDate>Tue, 27 Nov 2012 15:14:13 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=15287#15287</guid>
  </item> 
  <item>
   <title>Table Splitting :   I&amp;#039;m glad those are bugs....</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=13822#13822</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=613" rel="nofollow">stephenmcd1</a><br /><strong>Subject:</strong> 3487<br /><strong>Posted:</strong> 12-Jun-2012 at 1:52pm<br /><br /><p>I'm glad those are bugs. &nbsp;Thanks.</p><p>For the delete, I may have given a confusing example. &nbsp;I do expect that deleting the principal entity would cascade to the dependent. &nbsp;Whereas, deleting the dependent shouldn't necessarily cascade to the principal. &nbsp;In the code that I showed where deleting Customer didn't cascade to CustomerAddress, that was early on in my efforts when Customer was still the principal. &nbsp;Hopefully that is the behavior that you see (that the delete actually only cascades from dependent to principal) and hopefully you agree that one is a bug as well. &nbsp;Hopefully I explained it better this time.</p><p>Thanks again!</p>]]>
   </description>
   <pubDate>Tue, 12 Jun 2012 13:52:10 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=13822#13822</guid>
  </item> 
  <item>
   <title>Table Splitting :   Hi Stephen,I verified the...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=13801#13801</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> 3487<br /><strong>Posted:</strong> 07-Jun-2012 at 7:08pm<br /><br />Hi Stephen,<div>&nbsp;</div><div>I verified the first issue you stated and can confirm this is a bug. I'm filing a bug report on this regard.</div><div>&nbsp;</div><div>Regarding the second issue, i think this is just an effect of you calling Delete on the "Dependent" entity (i.e. in the Association). If you call Delete on CustomerAddress, (the "Principal" entity in the given situation) both entities will be Detached.</div><div>&nbsp;</div><div>As for the last issue. It also appear to be a bug and I'll be reporting it as well.</div><div>&nbsp;</div><div>Regards,</div><div>&nbsp;&nbsp; Silvio.</div>]]>
   </description>
   <pubDate>Thu, 07 Jun 2012 19:08:33 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=13801#13801</guid>
  </item> 
  <item>
   <title>Table Splitting : Does DevForce support setting...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=13771#13771</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=613" rel="nofollow">stephenmcd1</a><br /><strong>Subject:</strong> 3487<br /><strong>Posted:</strong> 06-Jun-2012 at 3:45pm<br /><br />Does DevForce support setting up Table Splitting in our Entity Framework model? &nbsp;Most things seem to work find with Table Splitting, but I've noticed a few odd behaviors that I think are bugs.<div><br></div><div><b><u>1.&nbsp;Referential&nbsp;Constraint seems to be reversed.</u></b></div><div><br></div><div>I followed the example of implementing table splitting on&nbsp;<a href="http://www.deveducate.com/blog/post/2010/12/14/Entity-Framework-Modeling-Table-Splitting.aspx" target="_blank">this page</a>&nbsp;(linked to from this&nbsp;<a href="http://drc.ideablade.com/xwiki/bin/view/&#068;ocumentati&#111;n/query-an&#111;nymous-projecti&#111;ns" target="_blank">DRC&nbsp;</a>page) which has you setup the&nbsp;Referential&nbsp;Contraint with the 'Principal' entity being the 'parent' and the 'Dependent' one being the child. &nbsp;For example, I took a Dev Force sample project and split up the Customer entity. &nbsp;I moved the address-related fields (Address, City, Region, PostalCode and Country) to a seperate CustomerAddress entity. &nbsp;It looks like this in the designer:</div><div><br></div><div><img src="http://www.ideablade.com/forum/uploads/613/CustomerCustomerAddress.png" height="370" width="471" border="0" /><br></div><div><br></div><div>To me, it seems like I should have the Customer entity be the principal and the CustomerAddress be the dependent. &nbsp;For example, this is how I expected to setup the&nbsp;Referential&nbsp;Constraint:</div><div><br></div><div><img src="http://www.ideablade.com/forum/uploads/613/ReferencialC&#111;nstraint.png" height="339" width="558" border="0" /><br></div><div>But doing it that way seems to confuse DevForce. &nbsp;For example, with the configuration above, the following code will break:<table width="99%"><tr><td><pre class="BBcode">var em = new NorthwindIBEntities();</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>//Make a customer</div><div>var customer = em.CreateEntity&lt;Customer&gt;();</div><div>customer.EntityAspect.AddToManager();</div><div><br></div><div>//Generate a new Guid as the Id</div><div>customer.CustomerID = Guid.NewGuid();</div><div><br></div><div>//Sanity check</div><div>DebugFns.Assert(customer.CustomerID != Guid.Empty);</div><div><br></div><div>//Make an address</div><div>var customerAddress = em.CreateEntity&lt;CustomerAddress&gt;();</div><div>customerAddress.EntityAspect.AddToManager();</div><div><br></div><div>//Sanity check - the ID is still set</div><div>DebugFns.Assert(customer.CustomerID != Guid.Empty);</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>//Assign the address</div><div>customer.CustomerAddress = customerAddress;</div><div><br></div><div>//Fails! &nbsp;The 'blank' Id from the CustomerAddress entity seems to have overwritten the 'real' ID on the Customer</div><div>DebugFns.Assert(customer.CustomerID != Guid.Empty);</pre></td></tr></table></div><div>I would have expected the Id that I set on the Customer to 'transfer' over to the CustomerAddress entity when I assigned the navigation property (which is the behavior I see in all other cases with DevForce which makes me think its a bug).</div><div><br></div><div>I can get around that problem by setting the CustomerID on the customerAddress entity before I assign the Navigation Property but that gets annoying (especially since in my real app, the code isn't nearly as simple as this....there are multipart keys and logic is spread all around).</div><div><br></div><div>Anyway, so I added some hacks to do manual copying of PK values before I assign the Navigation Property but then I ran into problems with deletes. &nbsp;This code also seems like it should work but doesn't:<table width="99%"><tr><td><pre class="BBcode">//Make a customer</div><div>var customer = em.CreateEntity&lt;Customer&gt;();</div><div>customer.EntityAspect.AddToManager();</div><div><br></div><div>//Generate a new Guid as the Id</div><div>customer.CustomerID = Guid.NewGuid();</div><div><br></div><div>//Sanity check</div><div>DebugFns.Assert(customer.CustomerID != Guid.Empty);</div><div><br></div><div>//Make an address</div><div>var customerAddress = em.CreateEntity&lt;CustomerAddress&gt;();</div><div>customerAddress.EntityAspect.AddToManager();</div><div><br></div><div>//Sanity check - the ID is still set</div><div>DebugFns.Assert(customer.CustomerID != Guid.Empty);</div><div><br></div><div>//HACK: Copy over the ID manually</div><div>customerAddress.CustomerID = customer.CustomerID;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>//Assign the address</div><div>customer.CustomerAddress = customerAddress;</div><div><br></div><div>//Passes now</div><div>DebugFns.Assert(customer.CustomerID != Guid.Empty);</div><div><br></div><div>//Delete the customer</div><div>customer.EntityAspect.Delete();</div><div><br></div><div>//Both entities should now be detached (since they never got saved, they become&nbsp;detached&nbsp;instead of 'Deleted')</div><div>DebugFns.Assert(customer.EntityAspect.EntityState == EntityState.Detached);</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>//Fails: The CustomerAddress is still in an Added state</div><div>DebugFns.Assert(customerAddress.EntityAspect.EntityState == EntityState.Detached);</pre></td></tr></table></div><div>After running into those two problems, I thought that maybe DevForce just doesn't support table splitting. &nbsp;But then I saw that your documentation mentions it so I took a second look. &nbsp;I noticed that if I switch around the order of the&nbsp;Referential&nbsp;Constraint so that CustomerAddress is the principal and Customer is the&nbsp;dependent&nbsp;one, all the test code above works as expected (no hacks necessary)!</div><div><br></div><div>I started down the road of just reversing the principal/dependent entities hoping that would solve all my problems - even though it felt very wrong and unintuitive....but then I ran into problems because of that. &nbsp;Now that Customer wasn't the principal, DevForce won't let me generate a temporary ID for it. &nbsp;For example, if I try to do:<table width="99%"><tr><td><pre class="BBcode">manager.GenerateId(myCustomer, Customer.PropertyMetadata.CustomerID)</pre></td></tr></table> it will give me an error saying:<table width="99%"><tr><td><pre class="BBcode">Cannot call GenerateId on 'Customer.CustomerID'. GenerateId cannot be called on ForeignKey properties ( even if they are also part of a PrimaryKey). &nbsp;Call GenerateId instead on the 'source' primary key</pre></td></tr></table> &nbsp;So instead, I'd be forced to call GenerateID on the CustomerAddress.CustomerID property....but that is awkward and sometimes impossible (part of the reason I want to do table splitting is so that the client doesn't always need to have the CustomerAddress entity after all!)</div><div><br></div><div><u><b>#2 Setting Navigation Properties on a Deleted Entity doesn't fixup the IDs</b></u></div><div><br></div><div>This one confused me for a while but in the end, it's very easy to reproduce. &nbsp;I'll build on the scenario given above with Customer and CustomerAddress. &nbsp;For this example, I'll have the&nbsp;Referential&nbsp;Constraint "reversed" so that setting Navigation Properties works. &nbsp;The difference in this case is that I delete the parent entity before assigning the navigation property.<table width="99%"><tr><td><pre class="BBcode">//Make a customer</div><div>var customer = em.CreateEntity&lt;Customer&gt;();</div><div>customer.EntityAspect.AddToManager();</div><div><br></div><div>//Generate a new Guid as the Id</div><div>customer.CustomerID = Guid.NewGuid();</div><div><br></div><div>//Sanity check</div><div>DebugFns.Assert(customer.CustomerID != Guid.Empty);</div><div><br></div><div>//Make an address</div><div>var customerAddress = em.CreateEntity&lt;CustomerAddress&gt;();</div><div>customerAddress.EntityAspect.AddToManager();</div><div><br></div><div>//Need to AcceptChanges before doing the delete otherwise the entity will just get detached</div><div>customer.EntityAspect.AcceptChanges();</div><div><br></div><div>//Delete the customer.</div><div>customer.EntityAspect.Delete();</div><div><br></div><div>//The customer still has its ID even though it is deleted</div><div>DebugFns.Assert(customer.CustomerID != Guid.Empty);</div><div><br></div><div>//Assign the address</div><div>customer.CustomerAddress = customerAddress;</div><div><br></div><div>//Since I reversed the Referential Constraint, the Customer.CustomerID property didn't get cleared</div><div>DebugFns.Assert(customer.CustomerID != Guid.Empty);</div><div><br></div><div>//Fails! &nbsp;The CustomerAddress.CustomerID is still empty....even though it got assigned to the navigation property!</div><div>DebugFns.Assert(customerAddress.CustomerID != Guid.Empty);</pre></td></tr></table></div><div>If I comment out the line that deletes the customer, this all works fine. &nbsp;Also, if I try it on other entities that aren't table-split ones, it all works fine (for example, I tested adding an Order to a deleted Customer and the Order.CustomerID property still got updated correctly).</div><div><br></div><div>Hopefully that is all clear. &nbsp;Thanks!</div>]]>
   </description>
   <pubDate>Wed, 06 Jun 2012 15:45:06 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3487&amp;PID=13771#13771</guid>
  </item> 
 </channel>
</rss>