<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Self-Tracking Entities: ApplyChanges and duplicate entities</title><link>http://blogs.msdn.com/b/diego/archive/2010/10/06/self-tracking-entities-applychanges-and-duplicate-entities.aspx</link><description>Some customers using the Self-Tracking Entities template we included in Visual Studio 2010 have ran into scenarios in which they call ApplyChanges passing a graph of entities that they put together in the client tier of their app, and then they get an</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Self-Tracking Entities: ApplyChanges and duplicate entities</title><link>http://blogs.msdn.com/b/diego/archive/2010/10/06/self-tracking-entities-applychanges-and-duplicate-entities.aspx#10298283</link><pubDate>Fri, 27 Apr 2012 00:37:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10298283</guid><dc:creator>Sean</dc:creator><description>&lt;p&gt;Just an additional note on only using the foreign key ID: I needed to be able to attach the same Product to PurchaseDetailLines and was getting the error, but my grid view uses the Product.Name property. Since everthing related to products was read-only I was able to do a foreach loop through the detail lines and set the Product entity equal to null. The foreign key kept and I was still able to use the referenced objects before the save. &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10298283" width="1" height="1"&gt;</description></item><item><title>re: Self-Tracking Entities: ApplyChanges and duplicate entities</title><link>http://blogs.msdn.com/b/diego/archive/2010/10/06/self-tracking-entities-applychanges-and-duplicate-entities.aspx#10270934</link><pubDate>Wed, 22 Feb 2012 09:22:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10270934</guid><dc:creator>JA Reyes - MCPD</dc:creator><description>&lt;p&gt;Hi @Martin,&lt;/p&gt;
&lt;p&gt;Could you show how you override the Equals method?&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10270934" width="1" height="1"&gt;</description></item><item><title>re: Self-Tracking Entities: ApplyChanges and duplicate entities</title><link>http://blogs.msdn.com/b/diego/archive/2010/10/06/self-tracking-entities-applychanges-and-duplicate-entities.aspx#10259372</link><pubDate>Sun, 22 Jan 2012 13:42:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10259372</guid><dc:creator>Martin Robins</dc:creator><description>&lt;p&gt;I ran into this problem a lot and found that it could also be resolved by overriding the Equals method of each entity class to compare the key values. Reading the above, are you saying that this should not have worked?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10259372" width="1" height="1"&gt;</description></item><item><title>re: Self-Tracking Entities: ApplyChanges and duplicate entities</title><link>http://blogs.msdn.com/b/diego/archive/2010/10/06/self-tracking-entities-applychanges-and-duplicate-entities.aspx#10124242</link><pubDate>Thu, 03 Feb 2011 09:49:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10124242</guid><dc:creator>Koen</dc:creator><description>&lt;p&gt;Thanks, this article provides some good insights.&lt;/p&gt;
&lt;p&gt;We use kind of the same technique as in work-around 3.&lt;/p&gt;
&lt;p&gt;Except we do it on the server-side, when a graph arrives at the server, right before calling, AcceptChanges. At this point, we search for duplicates and throw duplicates out.&lt;/p&gt;
&lt;p&gt;This only works when the duplicates don&amp;#39;t have changes them selves.&lt;/p&gt;
&lt;p&gt;But this works out fine in our scenarios, where like in this example,&lt;/p&gt;
&lt;p&gt;the duplicates usually come from a selection to link them to a Parent entity.&lt;/p&gt;
&lt;p&gt;This took us quite some time to figure out though.&lt;/p&gt;
&lt;p&gt;Some guidelines on what (and especially what not) is possibly with STE&amp;#39;s would be nice.&lt;/p&gt;
&lt;p&gt;Without such documentation, we keep running into &amp;quot;unexpected&amp;quot; issues like this, which take&lt;/p&gt;
&lt;p&gt;a lot of time to figure out.&lt;/p&gt;
&lt;p&gt;Still struggling with other issues, like re-linking detached entities.&lt;/p&gt;
&lt;p&gt;(see &lt;a rel="nofollow" target="_new" href="http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/4fadd41f-3157-43cb-b5e1-7def59aacdb5"&gt;social.msdn.microsoft.com/.../4fadd41f-3157-43cb-b5e1-7def59aacdb5&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;We feel like STE&amp;#39;s were/are not mature enough to go live with.&lt;/p&gt;
&lt;p&gt;Thanks for your time,&lt;/p&gt;
&lt;p&gt;Koen&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10124242" width="1" height="1"&gt;</description></item><item><title>re: Self-Tracking Entities: ApplyChanges and duplicate entities</title><link>http://blogs.msdn.com/b/diego/archive/2010/10/06/self-tracking-entities-applychanges-and-duplicate-entities.aspx#10108213</link><pubDate>Wed, 22 Dec 2010 17:07:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10108213</guid><dc:creator>mkamoski 1</dc:creator><description>&lt;p&gt;Diego --&lt;/p&gt;
&lt;p&gt;This is a GREAT post and so very helpful.&lt;/p&gt;
&lt;p&gt;I have a follow-up question.&lt;/p&gt;
&lt;p&gt;Regarding this...&lt;/p&gt;
&lt;p&gt;Only use Foreign Key values to manipulate associations:&lt;/p&gt;
&lt;p&gt;Every time you would do something like this:&lt;/p&gt;
&lt;p&gt;model.Make = make; //*1&lt;/p&gt;
&lt;p&gt;…replace it with this:&lt;/p&gt;
&lt;p&gt;model.MakeId = make.Id //*2&lt;/p&gt;
&lt;p&gt;...am I correct in assuming that the default behaviour of STEs would be that if one sets the FK property (as noted in *2) then at that point the corresponding object property (which is model.Make in this case) would be invalid, etiher null or pointing to some object that is not necessarily correct AND, I further assume, that once that modified &amp;quot;model&amp;quot; entity does get back to the Context and ApplyChanges() is called and SaveChanges() is called then (and only then) will the object property (model.Make) be set properly and ready to consume and use?&lt;/p&gt;
&lt;p&gt;What do you think?&lt;/p&gt;
&lt;p&gt;Please advise.&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;
&lt;p&gt;-- Mark Kamoski&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10108213" width="1" height="1"&gt;</description></item></channel></rss>