Looking for Suggestions on Implementing One-to-Many, Many-to-Many Patterns in SSDSI'm working on some SSDS examples that call for one-to-many and many-to-many relationships and haven't quite hit on a solution I like. I'm hoping some others are doing this already and are willing to share...<br><br><b>One-to-Many</b><br>Take object &quot;M1&quot; and associate that object with several child objects &quot;C1&quot;, &quot;C2&quot;, &quot;C3&quot;, &quot;Cn&quot; such that you can query for &quot;M1&quot; and get &quot;M1&quot; *and* the related children (&quot;C1-Cn&quot;) back for display. In T-SQL it would be:<br><br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px"></font><font style="color:blue">SELECT</font><font style="font-size:11px"> * </font><font style="color:blue">FROM</font><font style="font-size:11px"> master m </font><font style="color:rgb(128, 128, 128)">JOIN</font><font style="font-size:11px"> children c </font><font style="color:blue">on</font><font style="font-size:11px"> m.id=c=master_id </font></td></tr></tbody></table></div><br>Now, given the current state of queries in SSDS, I'm struggling with the best way to implement this.<br><br>I've come up with two possible strategies (there may be more, of course!)<br><br>1 - Create a single entity that contains both the master and essential child information (id and name). Essentially, building a giant bucket of data in a single entity<br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px"></font><font style="color:blue">&lt;</font><font style="font-size:11px">master</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">M1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">C1:Name1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">C2:Name2</font><font style="color:blue">&lt;/</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">Cn:NameN</font><font style="color:blue">&lt;/</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;/</font><font style="font-size:11px">master</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td> </td></tr></tbody></table></div>This has the advantage of a simple query pattern to return all the essential data up-front:<br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px">from e </font><font style="color:blue">in</font><font style="font-size:11px"> entities where e.Kind==</font><font style="color:blue">&quot;master&quot;</font><font style="font-size:11px"> </font></td></tr></tbody></table></div>But has the drawback of creating a 'compound' entity that can make updates a PITA and could possibly result in very large entity objects that could bog down processing.<br><br>-OR-<br><br>2 - Create typical master/child entities with a link-field in the child:<br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px"></font><font style="color:blue">&lt;</font><font style="font-size:11px">master</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">M1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td><font style="color:blue">&lt;/</font><font style="font-size:11px">master</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"> </td></tr><tr><td><font style="color:blue">&lt;</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">C1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">M1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;/</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td><font style="color:blue">&lt;</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">C2</font><font style="color:blue">&lt;/</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">M1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;/</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td><font style="color:blue">&lt;</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">Cn</font><font style="color:blue">&lt;/</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">M1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;/</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td> </td></tr></tbody></table></div>Has the advantage of clear separation of objects, no blocking issues for updates, etc. Has the disadvantage of no single SSDS query to return the requested data. Essentially, I now need the JOIN behavior if I want the data in a single pass:<br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px">from e </font><font style="color:blue">in</font><font style="font-size:11px"> entities where e.Kind==</font><font style="color:blue">&quot;master&quot;</font><font style="font-size:11px"> || (e[</font><font style="color:blue">&quot;master-id&quot;</font><font style="font-size:11px">]==e.Id &amp;&amp; e.Kind==</font><font style="color:blue">&quot;child&quot;</font><font style="font-size:11px">) select e </font></td></tr></tbody></table></div><br>Of course, that last example fails in SSDS. But only because of the rule about having to use constants for comparisons. So, instead I would need to make one query to get the list of master records and, for each entity returned, make a second request for all the children for that master record:<br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px">from m </font><font style="color:blue">in</font><font style="font-size:11px"> masters where m.Kind==</font><font style="color:blue">&quot;master&quot;</font><font style="font-size:11px"> select m </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">from c <font style="color:blue">in</font><font style="font-size:11px"> children where s.Kind==</font><font style="color:blue">&quot;child&quot;</font><font style="font-size:11px"> &amp;&amp; s[</font><font style="color:blue">&quot;master-id&quot;</font><font style="font-size:11px">]==</font><font style="color:blue">&quot;M1&quot;</font><font style="font-size:11px"> select c </font></td></tr><tr><td>from c <font style="color:blue">in</font><font style="font-size:11px"> children where s.Kind==</font><font style="color:blue">&quot;child&quot;</font><font style="font-size:11px"> &amp;&amp; s[</font><font style="color:blue">&quot;master-id&quot;</font><font style="font-size:11px">]==</font><font style="color:blue">&quot;M2&quot;</font><font style="font-size:11px"> select c </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">... </td></tr><tr><td>from c <font style="color:blue">in</font><font style="font-size:11px"> children where s.Kind==</font><font style="color:blue">&quot;child&quot;</font><font style="font-size:11px"> &amp;&amp; s[</font><font style="color:blue">&quot;master-id&quot;</font><font style="font-size:11px">]==</font><font style="color:blue">&quot;Mn&quot;</font><font style="font-size:11px"> select c </font></td></tr></tbody></table></div><br><b>Many-to-Many</b><br>Of course, it seems to get worse if I want to implement  &quot;Many-to-Many&quot; relationships.  Typically, I'd create &quot;master&quot;, &quot;child&quot;, and &quot;master-child&quot; collections with the &quot;master-child&quot; collection holding the many-to-many info:<br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px"></font><font style="color:blue">&lt;</font><font style="font-size:11px">master</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">M1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">    </font></td></tr><tr><td><font style="color:blue">&lt;/</font><font style="font-size:11px">master</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;</font><font style="font-size:11px">master</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">M2</font><font style="color:blue">&lt;/</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">    </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;/</font><font style="font-size:11px">master</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td> </td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">C1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;/</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td><font style="color:blue">&lt;</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">C1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td><font style="color:blue">&lt;/</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"> </td></tr><tr><td><font style="color:blue">&lt;</font><font style="font-size:11px">master-child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">MC1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">M1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">C1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td><font style="color:blue">&lt;/</font><font style="font-size:11px">master-child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;</font><font style="font-size:11px">master-child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">MC2</font><font style="color:blue">&lt;/</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">M2</font><font style="color:blue">&lt;/</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">C1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;/</font><font style="font-size:11px">master-child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td> </td></tr></tbody></table></div>Now I need to do additional queries! (get the master entities, get all the master-child entities for that master, get all the children for each master-child entity:<br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px"></font><font style="color:green">// get master list</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">from m <font style="color:blue">in</font><font style="font-size:11px"> masters where m.Kind==</font><font style="color:blue">&quot;master&quot;</font><font style="font-size:11px"> select m </font></td></tr><tr><td><font style="color:green">// for each master-child that belongs to the master list</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">from mc <font style="color:blue">in</font><font style="font-size:11px"> master_children where mc.Kind==</font><font style="color:blue">&quot;master-child&quot;</font><font style="font-size:11px"> &amp;&amp; s[</font><font style="color:blue">&quot;master-id&quot;</font><font style="font-size:11px">]==</font><font style="color:blue">&quot;M1&quot;</font><font style="font-size:11px"> select mc   </font></td></tr><tr><td><font style="color:green">// for each child in the master-child list</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">from c <font style="color:blue">in</font><font style="font-size:11px"> children where s.Kind==</font><font style="color:blue">&quot;child&quot;</font><font style="font-size:11px"> &amp;&amp; s[</font><font style="color:blue">&quot;child-id&quot;</font><font style="font-size:11px">]==</font><font style="color:blue">&quot;C1&quot;</font><font style="font-size:11px"> select c </font></td></tr><tr><td> </td></tr></tbody></table></div><br>So that's a bummer.<br><br>Am I missing some obvious work-arounds (<i>say &quot;yes&quot;, please say &quot;yes&quot;</i>)? Is a new sprint dropping soon (<i>like in the next hour</i>) that will make all this just go away (<i>tell me who I need to lean on, I'll get to 'em!</i>)?<br><br>Seriously, any pointers to examples solutions are most appreciated.  It will make my weekend all that much more rewarding.<br><br>Thanks for listenin'<br><br><br><br><hr align=left size=1 width="25%">Mike Amundsen [http://amundsen.com/blog/]© 2009 Microsoft Corporation. All rights reserved.Tue, 26 Aug 2008 02:37:55 Z39113823-97c3-4d12-9a4e-cb133bd7aa09http://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#39113823-97c3-4d12-9a4e-cb133bd7aa09http://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#39113823-97c3-4d12-9a4e-cb133bd7aa09Mike Amundsenhttp://social.msdn.microsoft.com/Profile/en-US/?user=Mike%20AmundsenLooking for Suggestions on Implementing One-to-Many, Many-to-Many Patterns in SSDSI'm working on some SSDS examples that call for one-to-many and many-to-many relationships and haven't quite hit on a solution I like. I'm hoping some others are doing this already and are willing to share...<br><br><b>One-to-Many</b><br>Take object &quot;M1&quot; and associate that object with several child objects &quot;C1&quot;, &quot;C2&quot;, &quot;C3&quot;, &quot;Cn&quot; such that you can query for &quot;M1&quot; and get &quot;M1&quot; *and* the related children (&quot;C1-Cn&quot;) back for display. In T-SQL it would be:<br><br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px"></font><font style="color:blue">SELECT</font><font style="font-size:11px"> * </font><font style="color:blue">FROM</font><font style="font-size:11px"> master m </font><font style="color:rgb(128, 128, 128)">JOIN</font><font style="font-size:11px"> children c </font><font style="color:blue">on</font><font style="font-size:11px"> m.id=c=master_id </font></td></tr></tbody></table></div><br>Now, given the current state of queries in SSDS, I'm struggling with the best way to implement this.<br><br>I've come up with two possible strategies (there may be more, of course!)<br><br>1 - Create a single entity that contains both the master and essential child information (id and name). Essentially, building a giant bucket of data in a single entity<br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px"></font><font style="color:blue">&lt;</font><font style="font-size:11px">master</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">M1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">C1:Name1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">C2:Name2</font><font style="color:blue">&lt;/</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">Cn:NameN</font><font style="color:blue">&lt;/</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;/</font><font style="font-size:11px">master</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td> </td></tr></tbody></table></div>This has the advantage of a simple query pattern to return all the essential data up-front:<br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px">from e </font><font style="color:blue">in</font><font style="font-size:11px"> entities where e.Kind==</font><font style="color:blue">&quot;master&quot;</font><font style="font-size:11px"> </font></td></tr></tbody></table></div>But has the drawback of creating a 'compound' entity that can make updates a PITA and could possibly result in very large entity objects that could bog down processing.<br><br>-OR-<br><br>2 - Create typical master/child entities with a link-field in the child:<br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px"></font><font style="color:blue">&lt;</font><font style="font-size:11px">master</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">M1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td><font style="color:blue">&lt;/</font><font style="font-size:11px">master</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"> </td></tr><tr><td><font style="color:blue">&lt;</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">C1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">M1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;/</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td><font style="color:blue">&lt;</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">C2</font><font style="color:blue">&lt;/</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">M1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;/</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td><font style="color:blue">&lt;</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">Cn</font><font style="color:blue">&lt;/</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">M1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;/</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td> </td></tr></tbody></table></div>Has the advantage of clear separation of objects, no blocking issues for updates, etc. Has the disadvantage of no single SSDS query to return the requested data. Essentially, I now need the JOIN behavior if I want the data in a single pass:<br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px">from e </font><font style="color:blue">in</font><font style="font-size:11px"> entities where e.Kind==</font><font style="color:blue">&quot;master&quot;</font><font style="font-size:11px"> || (e[</font><font style="color:blue">&quot;master-id&quot;</font><font style="font-size:11px">]==e.Id &amp;&amp; e.Kind==</font><font style="color:blue">&quot;child&quot;</font><font style="font-size:11px">) select e </font></td></tr></tbody></table></div><br>Of course, that last example fails in SSDS. But only because of the rule about having to use constants for comparisons. So, instead I would need to make one query to get the list of master records and, for each entity returned, make a second request for all the children for that master record:<br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px">from m </font><font style="color:blue">in</font><font style="font-size:11px"> masters where m.Kind==</font><font style="color:blue">&quot;master&quot;</font><font style="font-size:11px"> select m </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">from c <font style="color:blue">in</font><font style="font-size:11px"> children where s.Kind==</font><font style="color:blue">&quot;child&quot;</font><font style="font-size:11px"> &amp;&amp; s[</font><font style="color:blue">&quot;master-id&quot;</font><font style="font-size:11px">]==</font><font style="color:blue">&quot;M1&quot;</font><font style="font-size:11px"> select c </font></td></tr><tr><td>from c <font style="color:blue">in</font><font style="font-size:11px"> children where s.Kind==</font><font style="color:blue">&quot;child&quot;</font><font style="font-size:11px"> &amp;&amp; s[</font><font style="color:blue">&quot;master-id&quot;</font><font style="font-size:11px">]==</font><font style="color:blue">&quot;M2&quot;</font><font style="font-size:11px"> select c </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">... </td></tr><tr><td>from c <font style="color:blue">in</font><font style="font-size:11px"> children where s.Kind==</font><font style="color:blue">&quot;child&quot;</font><font style="font-size:11px"> &amp;&amp; s[</font><font style="color:blue">&quot;master-id&quot;</font><font style="font-size:11px">]==</font><font style="color:blue">&quot;Mn&quot;</font><font style="font-size:11px"> select c </font></td></tr></tbody></table></div><br><b>Many-to-Many</b><br>Of course, it seems to get worse if I want to implement  &quot;Many-to-Many&quot; relationships.  Typically, I'd create &quot;master&quot;, &quot;child&quot;, and &quot;master-child&quot; collections with the &quot;master-child&quot; collection holding the many-to-many info:<br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px"></font><font style="color:blue">&lt;</font><font style="font-size:11px">master</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">M1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">    </font></td></tr><tr><td><font style="color:blue">&lt;/</font><font style="font-size:11px">master</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;</font><font style="font-size:11px">master</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">M2</font><font style="color:blue">&lt;/</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">    </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;/</font><font style="font-size:11px">master</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td> </td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">C1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;/</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td><font style="color:blue">&lt;</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">C1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td><font style="color:blue">&lt;/</font><font style="font-size:11px">child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"> </td></tr><tr><td><font style="color:blue">&lt;</font><font style="font-size:11px">master-child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">MC1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">M1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">C1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td><font style="color:blue">&lt;/</font><font style="font-size:11px">master-child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;</font><font style="font-size:11px">master-child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px">MC2</font><font style="color:blue">&lt;/</font><font style="font-size:11px">s:Id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">  <font style="color:blue">&lt;</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">M2</font><font style="color:blue">&lt;/</font><font style="font-size:11px">master-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>  <font style="color:blue">&lt;</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px">C1</font><font style="color:blue">&lt;/</font><font style="font-size:11px">child-id</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;/</font><font style="font-size:11px">master-child</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td> </td></tr></tbody></table></div>Now I need to do additional queries! (get the master entities, get all the master-child entities for that master, get all the children for each master-child entity:<br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px"></font><font style="color:green">// get master list</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">from m <font style="color:blue">in</font><font style="font-size:11px"> masters where m.Kind==</font><font style="color:blue">&quot;master&quot;</font><font style="font-size:11px"> select m </font></td></tr><tr><td><font style="color:green">// for each master-child that belongs to the master list</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">from mc <font style="color:blue">in</font><font style="font-size:11px"> master_children where mc.Kind==</font><font style="color:blue">&quot;master-child&quot;</font><font style="font-size:11px"> &amp;&amp; s[</font><font style="color:blue">&quot;master-id&quot;</font><font style="font-size:11px">]==</font><font style="color:blue">&quot;M1&quot;</font><font style="font-size:11px"> select mc   </font></td></tr><tr><td><font style="color:green">// for each child in the master-child list</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">from c <font style="color:blue">in</font><font style="font-size:11px"> children where s.Kind==</font><font style="color:blue">&quot;child&quot;</font><font style="font-size:11px"> &amp;&amp; s[</font><font style="color:blue">&quot;child-id&quot;</font><font style="font-size:11px">]==</font><font style="color:blue">&quot;C1&quot;</font><font style="font-size:11px"> select c </font></td></tr><tr><td> </td></tr></tbody></table></div><br>So that's a bummer.<br><br>Am I missing some obvious work-arounds (<i>say &quot;yes&quot;, please say &quot;yes&quot;</i>)? Is a new sprint dropping soon (<i>like in the next hour</i>) that will make all this just go away (<i>tell me who I need to lean on, I'll get to 'em!</i>)?<br><br>Seriously, any pointers to examples solutions are most appreciated.  It will make my weekend all that much more rewarding.<br><br>Thanks for listenin'<br><br><br><br><hr align=left size=1 width="25%">Mike Amundsen [http://amundsen.com/blog/]Sat, 23 Aug 2008 00:22:30 Z2008-08-23T00:27:54Zhttp://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#5f298817-f010-4b31-b786-9d2d7e153035http://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#5f298817-f010-4b31-b786-9d2d7e153035c.c.chaihttp://social.msdn.microsoft.com/Profile/en-US/?user=c.c.chaiLooking for Suggestions on Implementing One-to-Many, Many-to-Many Patterns in SSDSMike,<br><br>I haven't consider the M:M scenario. As for 1:N association, it is interesting to see we both come up with identical solutions!!!!<br><br>Here is my findings:<br><br>Let say we have a sales ordering system. Order = master records, while Product  = detail records.<br><br>Method 1: Fat entity method.<br>Putting all child IDs together with master entity is good especially when you want to query how many master records are associated with the child, <br>e.g. from e in entities where e.Kind = &quot;Order&quot; &amp;&amp; e[&quot;CHILD_ProductA&quot;] == True<br>In this query, I can easily get all orders for Product A.<br><br>Negative side, the entity size tends to be very big, and slow when you only want to display a list of Order only for most of the time. <br>So, my thought is use this method when you always want to display master-detail records together.<br><br><br>Method 2: Foreign Key method <br>I use &quot;from e in entities where e.Kind == &quot;master&quot; || e.Kind == &quot;child&quot;&quot;.<br>Then use LINQ at client side to split the List&lt;Entity&gt; into List&lt;Master&gt; and List&lt;Child&gt;. Use LINQ again to join &amp; filter the Entities. <br>This method always require loading of excessive data. Tend to be inefficient for larger data set.<br><br><br>Conclusion:<br>Both methods are not efficient. After all SSDS is still in infancy state. Since I am working on desktop applications only, I am looking into the Sync Framework thing. <br><br>My idea is this: I will force the user to sync the data to local SQL CE cache for each session. Hence, my application always work on the data from local storage, it is much easier to enforce constraints, joins, etc. (Not to mention it is faster than loading data from the web..). And then sync any changes to SSDS at the end of the session. <br><br>In this way, it is easier for me to plan and build my applications, and any breaking changes from SSDS won't affect my apps directly. As for the sync thing, my current problems are there is no effective way to track changes in SSDS. And without transaction support, it is hard to handle exception in the middle of sync process (e.g. how to rollback?). <br><br>My current choice is to wait for post-PDC SSDS release before building my SSDS Sync Provider. Overall, my solution is to use SQL CE &lt;-&gt; Sync Fx &lt;-&gt;  SSDS architecture.<br><br><br><br><br>I hope to see anyone to come up with better solution.<br><br><font style="font-size:11px"><br></font><br> Sat, 23 Aug 2008 05:51:12 Z2008-08-23T05:51:12Zhttp://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#3336a00a-d87e-4f98-951d-ce4f2973909fhttp://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#3336a00a-d87e-4f98-951d-ce4f2973909fMike Amundsenhttp://social.msdn.microsoft.com/Profile/en-US/?user=Mike%20AmundsenLooking for Suggestions on Implementing One-to-Many, Many-to-Many Patterns in SSDSwell, like you say, at least we are heading in the same direction.<br><br>i'm considering storing the data in the classic &quot;foreign-key&quot; pattern and then constructing the &quot;fat entities&quot; along the way and caching those. then using the cache to build the final output to the user. my early examples might not get very large so scaling might not be an issue.<br><br>was hoping there were some other possible approaches...<br><br><br> <hr size="1" align="left" width="25%">Mike Amundsen [http://amundsen.com/blog/]Sat, 23 Aug 2008 09:26:08 Z2008-08-23T09:26:08Zhttp://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#9ad5f4ec-e90e-40bd-81a4-4cc00f1a1a97http://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#9ad5f4ec-e90e-40bd-81a4-4cc00f1a1a97c.c.chaihttp://social.msdn.microsoft.com/Profile/en-US/?user=c.c.chaiLooking for Suggestions on Implementing One-to-Many, Many-to-Many Patterns in SSDS<p>Well, another approach I can think of is to 'denormalize' your entities...storing all the master record's properties along with the child records. Obviously, it will be tough when updating the master record.<br><br>Even if SSDS introduces INNER JOIN, I still need left outer join and other types of join. And ideally, I can do &quot;from e in entities select e.Id, e[&quot;Prop1&quot;], e.[&quot;Prop2&quot;]&quot;, otherwise, I am still loading more data than I need. So, in the end, the JOIN problem won't be sovled within one single SSDS release...we still need to wait longer and longer...<br><br>Having said that, I hope SSDS includes transaction support in the coming release. In many cases, it make more sense to persist the master-detail records within single transaction.</p>Sat, 23 Aug 2008 11:20:16 Z2008-08-23T11:20:16Zhttp://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#bef12289-b3ff-465a-92d8-f7c708abf373http://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#bef12289-b3ff-465a-92d8-f7c708abf373Mike Amundsenhttp://social.msdn.microsoft.com/Profile/en-US/?user=Mike%20AmundsenLooking for Suggestions on Implementing One-to-Many, Many-to-Many Patterns in SSDSWell, I don't think JOIN is the &quot;missing link&quot; here.  This is valid SSDS query that does a in-container JOIN:<br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px">from e </font><font style="color:blue">in</font><font style="font-size:11px"> entities where e.Kind==</font><font style="color:blue">&quot;master&quot;</font><font style="font-size:11px"> || (e[</font><font style="color:blue">&quot;master-id&quot;</font><font style="font-size:11px">]==</font><font style="color:blue">&quot;123&quot;</font><font style="font-size:11px"> &amp;&amp; e.Kind==</font><font style="color:blue">&quot;child&quot;</font><font style="font-size:11px">) select e </font></td></tr></tbody></table></div><br> <br>The problem, IMHO, is that this only returns the MASTER and CHILD set for *one* master (&quot;123&quot;). I need a way to do this for a *set* of masters:<br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px">from e </font><font style="color:blue">in</font><font style="font-size:11px"> entities where e.Kind==</font><font style="color:blue">&quot;master&quot;</font><font style="font-size:11px"> || (e[</font><font style="color:blue">&quot;master-id&quot;</font><font style="font-size:11px">]==e.Id &amp;&amp; e.Kind==</font><font style="color:blue">&quot;child&quot;</font><font style="font-size:11px">) select e </font></td></tr></tbody></table></div><br>The above query breaks the &quot;constants for comparisons&quot; rule. Also, it does not properly scope the &quot;e.Id&quot; value to only use s.Kind==&quot;master.&quot; <br><br>One way to fix this might be to allow us to present a set of queries to be run by SSDS with the results of the final query returned to us:<br><br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px"></font><font style="color:green">// get a collection of master records</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">from m <font style="color:blue">in</font><font style="font-size:11px"> masters where m.Kind==</font><font style="color:blue">&quot;master&quot;</font><font style="font-size:11px"> select m </font></td></tr><tr><td> </td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:green">// get a collection of child records using each master record Id (m.Id)</font><font style="font-size:11px"> </font></td></tr><tr><td>from r <font style="color:blue">in</font><font style="font-size:11px"> results where r.Kind==</font><font style="color:blue">&quot;child&quot;</font><font style="font-size:11px"> &amp;&amp; r[</font><font style="color:blue">&quot;master-id&quot;</font><font style="font-size:11px">]==(m.Id </font><font style="color:blue">in</font><font style="font-size:11px"> master) select r </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"> </td></tr><tr><td><font style="color:green">// return both the master record set *and* the child record set</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">return</font><font style="font-size:11px"> m,r </font></td></tr></tbody></table></div><br>Just on possibility.<br><br><hr size="1" align="left" width="25%">Mike Amundsen [http://amundsen.com/blog/]Sat, 23 Aug 2008 16:05:34 Z2008-08-23T16:05:34Zhttp://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#3d29f447-9c60-42cc-8af3-9a0f455c5541http://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#3d29f447-9c60-42cc-8af3-9a0f455c5541Dave Robinson - SQL Azurehttp://social.msdn.microsoft.com/Profile/en-US/?user=Dave%20Robinson%20-%20SQL%20AzureLooking for Suggestions on Implementing One-to-Many, Many-to-Many Patterns in SSDSHave you thought about the following?<br><br> <p>&lt;master&gt;  <br>  &lt;s:Id&gt;M1&lt;/s:Id&gt;<br>  &lt;fkId&gt;123&lt;/fkid&gt;<br>&lt;/master&gt;  <br>&lt;child&gt;  <br>  &lt;s:Id&gt;C1&lt;/child&gt;  <br>  &lt;fkId&gt;123&lt;/fkid&gt;<br>&lt;/child&gt;  <br>&lt;child&gt;  <br>  &lt;s:Id&gt;C2&lt;/child&gt;  <br>  &lt;fkId&gt;123&lt;/fkid&gt;<br>&lt;/child&gt;  </p> <p>from e in entities where e[&quot;fkid&quot;] == &quot;123&quot; select</p>Mon, 25 Aug 2008 17:32:08 Z2008-08-25T17:34:15Zhttp://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#75572c38-c4f7-4b58-becf-536ea6f2ddc0http://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#75572c38-c4f7-4b58-becf-536ea6f2ddc0Mike Amundsenhttp://social.msdn.microsoft.com/Profile/en-US/?user=Mike%20AmundsenLooking for Suggestions on Implementing One-to-Many, Many-to-Many Patterns in SSDSdave:<br><br>if i understand your post, this is about getting the master and related child records for a single master in one query. that's cool.  i think your example might perform better than the one i posted earlier:<br><font style="font-size:11px">from e </font><font style="color:blue">in</font><font style="font-size:11px"> entities where e.Kind==</font><font style="color:blue">&quot;master&quot;</font><font style="font-size:11px"> || (e[</font><font style="color:blue">&quot;master-id&quot;</font><font style="font-size:11px">]==</font><font style="color:blue">&quot;123&quot;</font><font style="font-size:11px"> &amp;&amp; e.Kind==</font><font style="color:blue">&quot;child&quot;</font><font style="font-size:11px">) select e <br><br></font>but the challenge i have is that i need to get the master and related children for a *set* of master records. bascially, where i don't know the master id when i make the query.  to use your example, i think i need something like this: <br><br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px">from m </font><font style="color:blue">in</font><font style="font-size:11px"> masters where m.Kind select m </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">foreach m.Id <font style="color:blue">in</font><font style="font-size:11px"> masters </font></td></tr><tr><td>{ </td></tr><tr><td style="background-color:rgb(247, 247, 247)">  from e <font style="color:blue">in</font><font style="font-size:11px"> entities where e[</font><font style="color:blue">&quot;fkid&quot;</font><font style="font-size:11px">] == m.Id select e </font></td></tr><tr><td>} </td></tr><tr><td style="background-color:rgb(247, 247, 247)"> </td></tr></tbody></table></div><br><br> <hr size="1" align="left" width="25%">Mike Amundsen [http://amundsen.com/blog/]Mon, 25 Aug 2008 18:26:37 Z2008-08-25T18:26:37Zhttp://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#9674fb91-c9c3-4c12-becd-22174638e345http://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#9674fb91-c9c3-4c12-becd-22174638e345Dave Robinson - SQL Azurehttp://social.msdn.microsoft.com/Profile/en-US/?user=Dave%20Robinson%20-%20SQL%20AzureLooking for Suggestions on Implementing One-to-Many, Many-to-Many Patterns in SSDS Mike,<br><br>What is your scenario like? Just trying to understand it better. A common pattern is to present the list of master records and when on is selected, show the associated child records. I gather you are trying to either..<br><br><br>Get ALL Master and Child records in one query<br><br>or<br><br>Get a subset of Master and Child records with something similiar to a IN clause<br><br><br>Sorry if I am being thick...its monday<br><br>-DaveMon, 25 Aug 2008 19:34:38 Z2008-08-25T19:34:38Zhttp://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#7a8384db-599f-4d64-be6e-65a2671c0214http://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#7a8384db-599f-4d64-be6e-65a2671c0214Mike Amundsenhttp://social.msdn.microsoft.com/Profile/en-US/?user=Mike%20AmundsenLooking for Suggestions on Implementing One-to-Many, Many-to-Many Patterns in SSDSDAve:<br><br>thanks for the interest. <br><br>think of a tag list for an entry. <br><b><u>my latest important blog post</u><br>- tagged as <u>tech</u>, <u>breaking-news</u>, <u>potential-bombshells</u><br></b><br>The single query you supplied would pull the data for that display easily - as long as I have a key|lookup value for the post itself.<br><br>then make that an entire page of items:<br><b><u>my latest important blog post</u><br> - tagged as <u>tech</u>, <u>breaking-news</u>, <u>potential-bombshells</u><br></b><b><u><br>another important blog post</u><br> - tagged as <u>tech</u>, <u>personal</u>, <u>embarrassing</u><br> </b><br><b><u>an important blog post</u><br> - tagged as <u>tech</u>, <u>important</u><u></u><br> </b><br><b><u>my latest important blog post</u><br> - tagged as <u>tech</u>, <u>breaking-news</u>, <u>potential-bombshells</u><br></b><b><u><br></u></b>now I have a list of posts. i need to get that list of posts and all the children for each of those posts. I would like to do this with a single SSDS query, but haven't found a way to do it. <br><br><br><br><br><hr size="1" align="left" width="25%">Mike Amundsen [http://amundsen.com/blog/]Mon, 25 Aug 2008 20:15:24 Z2008-08-25T20:15:24Zhttp://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#8faebacd-635d-4731-aa54-f6a9943e9412http://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#8faebacd-635d-4731-aa54-f6a9943e9412Dave Robinson - SQL Azurehttp://social.msdn.microsoft.com/Profile/en-US/?user=Dave%20Robinson%20-%20SQL%20AzureLooking for Suggestions on Implementing One-to-Many, Many-to-Many Patterns in SSDSMike,<br><br>Today, your best bet would be the pattern you describe above.<br><br> <div style="font-size:11px;overflow:auto;line-height:100%! important;font-family:Courier New;background-color:white"> <table style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255,255,255);border-right-width:0px" cellspacing=0 cellpadding=0> <colgroup> <col style="padding-left:10px;font-size:11px;font-family:Courier New;white-space:nowrap"> <tbody> <tr> <td><font style="font-size:11px">from m </font><font style="color:blue">in</font><font style="font-size:11px"> masters where m.Kind select m </font></td></tr> <tr> <td style="background-color:rgb(247,247,247)">foreach m.Id <font style="color:blue">in</font><font style="font-size:11px"> masters </font></td></tr> <tr> <td>{ </td></tr> <tr> <td style="background-color:rgb(247,247,247)">  from e <font style="color:blue">in</font><font style="font-size:11px"> entities where e[</font><font style="color:blue">&quot;fkid&quot;</font><font style="font-size:11px">] == m.Id select e </font></td></tr> <tr> <td>} </td></tr></tbody></table></div><br><br>Come the PDC, there will be some query language enhancements that will make this much easier. If I was you, I would go signup for PDC and see it firsthand :)<br><br>-DaveMon, 25 Aug 2008 23:39:49 Z2008-08-25T23:39:49Zhttp://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#52ee92a3-e90e-4853-b10e-b8be50abdf26http://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#52ee92a3-e90e-4853-b10e-b8be50abdf26Mike Amundsenhttp://social.msdn.microsoft.com/Profile/en-US/?user=Mike%20AmundsenLooking for Suggestions on Implementing One-to-Many, Many-to-Many Patterns in SSDSfirst, it's nice to know  that i'm on the right track.<br><br>second, it's good to hear that things iwll be getting easier soon.<br><br>lastly, look's like i'll have to see all this up front personal-like.<br><br>anyone else here planning on attending the PDC in october?<br><br> <hr size="1" align="left" width="25%">Mike Amundsen [http://amundsen.com/blog/]Tue, 26 Aug 2008 01:55:21 Z2008-08-26T01:55:21Zhttp://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#beb24811-9e23-4cf6-bebb-6f3241a8831ehttp://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/39113823-97c3-4d12-9a4e-cb133bd7aa09#beb24811-9e23-4cf6-bebb-6f3241a8831eMike Amundsenhttp://social.msdn.microsoft.com/Profile/en-US/?user=Mike%20AmundsenLooking for Suggestions on Implementing One-to-Many, Many-to-Many Patterns in SSDSDave:<br><br>for now, i plan to implement the first pattern, within the client, using an async call spawned for each master record.  this will cost a bit for the client, but will be more responsive than building it all on the server before sending it to the client.<br><br>thanks for the feedback and i'm looking forward to the new features around PDC-timeframe.<br><br><br> <hr size="1" align="left" width="25%">Mike Amundsen [http://amundsen.com/blog/]Tue, 26 Aug 2008 02:37:55 Z2008-08-26T02:37:55Z