<?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 : Problem with 3 level table relationship</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Problem with 3 level table relationship</description>
  <pubDate>Tue, 12 May 2026 21:33:53 -700</pubDate>
  <lastBuildDate>Mon, 25 Mar 2013 14:03:49 -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=4017</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>Problem with 3 level table relationship : Excellent!  Thanks for the update....</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4017&amp;PID=16125#16125</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=11" rel="nofollow">kimj</a><br /><strong>Subject:</strong> 4017<br /><strong>Posted:</strong> 25-Mar-2013 at 2:03pm<br /><br />Excellent!  Thanks for the update.]]>
   </description>
   <pubDate>Mon, 25 Mar 2013 14:03:49 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4017&amp;PID=16125#16125</guid>
  </item> 
  <item>
   <title>Problem with 3 level table relationship : Everything seems to be working...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4017&amp;PID=16124#16124</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> 4017<br /><strong>Posted:</strong> 25-Mar-2013 at 1:57pm<br /><br />Everything seems to be working in 6.1.12. &nbsp;The (failing) code I presented above works perfectly in the new version. &nbsp;Many thanks!]]>
   </description>
   <pubDate>Mon, 25 Mar 2013 13:57:35 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4017&amp;PID=16124#16124</guid>
  </item> 
  <item>
   <title>Problem with 3 level table relationship :   Yes.   Changes should now...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4017&amp;PID=15962#15962</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=11" rel="nofollow">kimj</a><br /><strong>Subject:</strong> 4017<br /><strong>Posted:</strong> 07-Mar-2013 at 11:13am<br /><br />Yes.  &nbsp; Changes should now cascade to grandchildren (and beyond - but that would be a very odd model).&nbsp;&nbsp; ]]>
   </description>
   <pubDate>Thu, 07 Mar 2013 11:13:05 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4017&amp;PID=15962#15962</guid>
  </item> 
  <item>
   <title>Problem with 3 level table relationship : That is great news Kim! To be...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4017&amp;PID=15961#15961</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> 4017<br /><strong>Posted:</strong> 07-Mar-2013 at 10:14am<br /><br />That is great news Kim! &nbsp;To be honest, I was half expecting this to just be a 'limitation' of the system. &nbsp;I'm glad it will work as expected in the next release.<div><br></div><div>Is there any chance that these fixes could affect other problems I've had with 3-level table relationships...specifically issue #1 in <a href="http://www.ideablade.com/forum/forum_posts.asp?TID=3465&amp;PID=13860&amp;title=forcing-early-id-fixup#13860" target="_blank">this post</a>. &nbsp;I know it's a long shot but I have to ask :-).</div>]]>
   </description>
   <pubDate>Thu, 07 Mar 2013 10:14:29 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4017&amp;PID=15961#15961</guid>
  </item> 
  <item>
   <title>Problem with 3 level table relationship :   A couple of things going on...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4017&amp;PID=15957#15957</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=11" rel="nofollow">kimj</a><br /><strong>Subject:</strong> 4017<br /><strong>Posted:</strong> 06-Mar-2013 at 7:31pm<br /><br />A couple of things going on here.<div>&nbsp;</div>First, the odd results when setting the FK ID field directly (detail.ProductID = 200) is a bug, due to incorrect handling of the multi-part key.&nbsp; <div>&nbsp;</div><div>Second, the exception when setting the nav property (detail.Product = product2) - The exception is clumsily trying to stop a cascade to dependent entities, even though, as you note, this can be done via other code paths.</div><div>&nbsp;</div><div>We should have both problems fixed in the upcoming 6.1.12 release.  You should then be able to modify the key field in either way and have the change cascaded to multiple levels of dependent entities. </div>]]>
   </description>
   <pubDate>Wed, 06 Mar 2013 19:31:16 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4017&amp;PID=15957#15957</guid>
  </item> 
  <item>
   <title>Problem with 3 level table relationship : We have an annoying table structure...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4017&amp;PID=15939#15939</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> 4017<br /><strong>Posted:</strong> 05-Mar-2013 at 9:46am<br /><br />We have an annoying table structure (that we unfortunately have to live with for legacy reasons) and we are running into some odd problems when we use it in certain ways. &nbsp;I'm not sure whether we are just trying to do something that isn't support or what.<div><br></div><div>To reproduce the problem in a simpler context, I took the&nbsp;<span style=": rgb251, 251, 253; line-height: 1.4;">NorthwindIB database and added an extra table so that I could have a 3-level relationship. &nbsp;The model now looks like this:</span></div><div><span style=": rgb251, 251, 253; line-height: 1.4;"><br></span></div><div><span style=": rgb251, 251, 253; line-height: 1.4;"><img src="uploads/613/3LevelRelati&#111;nship.png" height="421" width="612" border="0" /><br></span></div><div><span style=": rgb251, 251, 253; line-height: 1.4;"><br></span></div><div><span style=": rgb251, 251, 253; line-height: 1.4;">With a model like that, the following unit test will fail:<table width="99%"><tr><td><pre class="BBcode"></span>&nbsp; &nbsp; &nbsp; &nbsp; public void TestThreeLevels()</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var em = new EntityManager(shouldConnect: false);</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Make two products - '100' and '200'</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var product1 = em.CreateEntity&lt;Product&gt;();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; product1.EntityAspect.AddToManager();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; product1.ProductID = 100;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var product2 = em.CreateEntity&lt;Product&gt;();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; product2.EntityAspect.AddToManager();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; product2.ProductID = 200;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Create an Order</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var order = em.CreateEntity&lt;Order&gt;();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; order.EntityAspect.AddToManager();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; order.OrderID = 1;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //And one detail that is currently pointing to Product 100</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var detail = em.CreateEntity&lt;OrderDetail&gt;();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; detail.EntityAspect.AddToManager();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; detail.ProductID = 100;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; order.OrderDetails.Add(detail);</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Make an extra detail entity</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var extra = em.CreateEntity&lt;OrderDetailExtraDetail&gt;();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; extra.EntityAspect.AddToManager();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; extra.DetailID = 3;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; detail.OrderDetailRevisions.Add(extra);</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Sanity check to make sure the extra entity is how we expect it</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assert.AreEqual(1, extra.OrderID);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assert.AreEqual(100, extra.ProductID);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assert.AreEqual(3, extra.DetailID);</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Now switch the detail to Product 200. &nbsp;I would expect this change to cascade&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp;to its child (the extra detail). &nbsp;It sort of cascades but not in any sensible way...</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; detail.ProductID = 200;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //This fails: &nbsp;the order ID somehow got set to 200? &nbsp;But that was the Product ID not the Order ID</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assert.AreEqual(1, extra.OrderID);</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //This also fails: The Product ID wasn't changed - it is still 100</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assert.AreEqual(200, extra.ProductID);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assert.AreEqual(3, extra.DetailID);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }<span style=": rgb251, 251, 253; line-height: 1.4;"></pre></td></tr></table></span></div><div><span style=": rgb251, 251, 253; line-height: 1.4;"><br></span></div><div><span style=": rgb251, 251, 253; line-height: 1.4;">That behavior seems very, very strange (and in fact took us a long time to track down why the OrderID was all of a sudden pointing to something very wrong).</span></div><div><span style=": rgb251, 251, 253; line-height: 1.4;"><br></span></div><div><span style=": rgb251, 251, 253; line-height: 1.4;">Once I tracked down the problem, I tried to use the navigation property to change the product. &nbsp;So instead of <font face="Courier New, Courier, mono">detail.ProductID = 200</font>, I used <font face="Courier New, Courier, mono">detail.Product = product2</font>. &nbsp;(Note in our app, we don't even have that navigation so it's not really an option but I wanted to try it anyway in my smaller app). &nbsp;When I did that, I got the following error:</span></div><div><span style=": rgb251, 251, 253; line-height: 1.4;"><br></span></div><blockquote style="margin: 0 0 0 40px; border: n&#111;ne; padding: 0px;"><div><font face="Courier New, Courier, mono">System.InvalidOperationException: You may not change the entity’s EntityKey (currently ‘OrderDetail: 1,100’) while any of its related, dependent entities are in the entity cache. Are you sure you want to change the EntityKey? Consider reordering your operations such that you set the EntityKey first. Alternatively you could detach the entity or remove its dependent entities before trying again but be aware that you risk orphaning the dependent entities.</font></div></blockquote><div><span style=": rgb251, 251, 253; line-height: 1.4;"><br></span></div><div><span style=": rgb251, 251, 253; line-height: 1.4;">So that got me thinking that I might just be doing something wrong? &nbsp;Maybe this isn't a supported scenario for DevForce (which would be very sad - and combined with the other limitation of 3-level relationships <a href="http://www.ideablade.com/forum/forum_posts.asp?TID=3465&amp;PID=13860&amp;title=forcing-early-id-fixup#13860" target="_blank">I ran into previously</a>, means 3 level relationships can be very fragile and dangerous to use). &nbsp;I'm hoping this is just a bug or I'm doing something small wrong. &nbsp;I really hope this isn't the expected behavior.</span></div><div><span style=": rgb251, 251, 253; line-height: 1.4;"><br></span></div><div>A couple of extra things:</div><div><ol><li>If this scenario is really not supported, I think that exception should be thrown if you change the FK value in addition to the navigation property. &nbsp;If I hadn't tried to reproduce this in a separate project where there was a navigation property, I would have never known that I was doing something bad.</li><li>The exception message seems a bit oversimplified. &nbsp;I know there are plenty of times when the PK can be changed and it correctly updates related entities. &nbsp;The whole idea of temporary ID fixup pretty much relies on the fact that changes to the PK will cascade around the object graph. &nbsp;Also, in my test code above, if I replace <font face="Courier New, Courier, mono">detail.ProductID = 200</font> with <font face="Courier New, Courier, mono">detail.OrderID = 42</font>, that does correctly cascade the new value down to the extra detail....so I know it can work in some cases.</li></ol></div><div><span style=": rgb251, 251, 253; line-height: 1.4;">Thanks.</span></div>]]>
   </description>
   <pubDate>Tue, 05 Mar 2013 09:46:01 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4017&amp;PID=15939#15939</guid>
  </item> 
 </channel>
</rss>