<?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 : Getting state of many to many relation</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Getting state of many to many relation</description>
  <pubDate>Mon, 13 Apr 2026 14:41:25 -700</pubDate>
  <lastBuildDate>Thu, 08 Jul 2010 14:47:31 -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=1946</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>Getting state of many to many relation : Ok, got it. Actually, the only...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1946&amp;PID=7571#7571</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=4" rel="nofollow">GregD</a><br /><strong>Subject:</strong> 1946<br /><strong>Posted:</strong> 08-Jul-2010 at 2:47pm<br /><br />Ok, got it. Actually, the only material difference between what my code does and the scenario you described is the save, which I didn't do. Add that and my code fails as yours does.<br /><br />I'm filing a bug report on this. Looks like we might be trying to insert the linking record (for the add) without having first performed the delete (for the Remove). Alternatively, we might be able to identify that the two actions cancel each other out and do neither a delete nor an insert.<br /><br />Thank you for calling the problem to our attention.<br /><span style="font-size:10px"><br /><br />Edited by GregD - 08-Jul-2010 at 2:48pm</span>]]>
   </description>
   <pubDate>Thu, 08 Jul 2010 14:47:31 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1946&amp;PID=7571#7571</guid>
  </item> 
  <item>
   <title>Getting state of many to many relation : My scenario is a little more involved...I&amp;#039;ll...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1946&amp;PID=7551#7551</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=838" rel="nofollow">rhaney</a><br /><strong>Subject:</strong> 1946<br /><strong>Posted:</strong> 07-Jul-2010 at 4:02pm<br /><br /><P>My scenario is a little more involved...I'll use the entities in your example...note this is all from a single entity manager.</P><DIV>Get all territories, store them in a list.</DIV><DIV>&nbsp;</DIV><DIV>Get an Employee with Territories using query.Include(e =&gt; e.Territories).</DIV><DIV>&nbsp;</DIV><DIV>Remove a territory from employee.Territories.</DIV><DIV>&nbsp;</DIV><DIV>Find the same territory in the "all territories list" and add it to the employee.</DIV><DIV>&nbsp;</DIV><DIV>Save.</DIV><DIV>&nbsp;</DIV><DIV>In my scenario, I get a FK violation.</DIV>]]>
   </description>
   <pubDate>Wed, 07 Jul 2010 16:02:01 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1946&amp;PID=7551#7551</guid>
  </item> 
  <item>
   <title>Getting state of many to many relation : I think this may be the result...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1946&amp;PID=7549#7549</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=4" rel="nofollow">GregD</a><br /><strong>Subject:</strong> 1946<br /><strong>Posted:</strong> 07-Jul-2010 at 3:08pm<br /><br />I think this may be the result of something your UI is doing or not doing.<br /><br />I tried the following:<br /><br /><table width="99%"><tr><td><pre class="BBcode"><br />&nbsp;&nbsp;&nbsp;&nbsp;public void BasicQuerySyntaxQuery() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_em1.ExecuteQueryAsync(_em1.Employees.Where(c =&gt; c.Country == "USA"), GotEmployees, null);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;private void GotEmployees(EntityQueryOperation&lt;Employee&gt; args) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_currentEmployee = args.Results.FirstOrDefault();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_currentEmployee.Territories.PendingEntityListResolved += new EventHandler&lt;PendingEntityListResolvedArgs&lt;Territory&gt;&gt;(Territories_PendingEntityListResolved);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;void Territories_PendingEntityListResolved(object sender, PendingEntityListResolvedEventArgs&lt;Territory&gt; e) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Territory aTerritory = e.ResolvedEntities&#091;0&#093;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_currentEmployee.Territories.Remove(aTerritory);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_currentEmployee.Territories.Add(aTerritory);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br /></pre></td></tr></table><br /><br />If I throw code in there to output results ...<br /><br /><table width="99%"><tr><td><pre class="BBcode"><br />&nbsp;&nbsp;&nbsp;&nbsp;public void BasicQuerySyntaxQuery() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_localOutput.Append(String.Format("&#091;{0}&#093; Started...\n", _nameBasicQuerySyntaxQuery));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Utility.ResetEntityManager(_em1);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_em1.ExecuteQueryAsync(_em1.Employees.Where(c =&gt; c.Country == "USA"), GotEmployees, null);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;private void GotEmployees(EntityQueryOperation&lt;Employee&gt; args) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_localOutput.Append(string.Format("&#091;{0}&#093; Retrieved {1} customers\n",<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _nameBasicQuerySyntaxQuery, args.Results.Count()));<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_currentEmployee = args.Results.FirstOrDefault();<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_currentEmployee.Territories.PendingEntityListResolved += new EventHandler&lt;PendingEntityListResolvedEventArgs&lt;Territory&gt;&gt;(Territories_PendingEntityListResolved);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Order newOrder = new Order();<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Utility.FlushOutputBuffer(_localOutput, _resultsReporter);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;void Territories_PendingEntityListResolved(object sender, PendingEntityListResolvedEventArgs&lt;Territory&gt; e) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_localOutput.Append(string.Format("&#091;{0}&#093; Retrieved {1} related territories for Employee {2}\n",<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _nameBasicQuerySyntaxQuery, e.ResolvedEntities.Count, _currentEmployee.LastName));<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Territory aTerritory = e.ResolvedEntities&#091;0&#093;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_currentEmployee.Territories.Remove(aTerritory);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_localOutput.Append(string.Format("&#091;{0}&#093; No. of territories after removing one: {1}\n",<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _nameBasicQuerySyntaxQuery, _currentEmployee.Territories.Count));<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_currentEmployee.Territories.Add(aTerritory);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_localOutput.Append(string.Format("&#091;{0}&#093; No. of territories after adding the removed one back: {1}\n",<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _nameBasicQuerySyntaxQuery, _currentEmployee.Territories.Count));<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Utility.FlushOutputBuffer(_localOutput, _resultsReporter);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /></pre></td></tr></table><br /><br />... then I get these:<br /><br /><img src="uploads/4/M2MRemoveReAdd.jpg" border="0" /><br /><br />No errors!]]>
   </description>
   <pubDate>Wed, 07 Jul 2010 15:08:51 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1946&amp;PID=7549#7549</guid>
  </item> 
  <item>
   <title>Getting state of many to many relation : I have two entities, Group and...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1946&amp;PID=7529#7529</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=838" rel="nofollow">rhaney</a><br /><strong>Subject:</strong> 1946<br /><strong>Posted:</strong> 06-Jul-2010 at 3:53pm<br /><br /><P>I have two entities, Group and Person, that are joined together in a many-to-many relationship.&nbsp; When my UI first loads, I have present a list of groups.&nbsp; When the user selects a group, I present the list of current people in that group.&nbsp;&nbsp;</P><DIV>In my UI, if the user accidentally&nbsp;removes a person from a group and re-adds&nbsp;the&nbsp;person to the same group and tries to save, they get a FK violation error.</DIV><DIV>&nbsp;</DIV><DIV>What I haven't been able to figure out to do is detect if the Person instance is pending removal from the group.&nbsp; If I can detect and rollback the delete, I should be OK.</DIV><DIV>&nbsp;</DIV><DIV>Ideally, I just add the person to the group again, and DevForce figures out that the relation already exists.</DIV><DIV>&nbsp;</DIV><DIV>I thought about creating an intermediate entity that joins the Group and Person, but that just seems a kludge when I don't have additional properties.</DIV><DIV>&nbsp;</DIV><DIV>Thoughts?</DIV>]]>
   </description>
   <pubDate>Tue, 06 Jul 2010 15:53:08 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1946&amp;PID=7529#7529</guid>
  </item> 
 </channel>
</rss>