<?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>Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx</link><description>Linq is a great technology to manage data directly from your .Net language. One of its features is grouping. Many people understand grouping like it is defined in Sql. Linq is implementing grouping quite the same way. Let's discover this syntax and how</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Geek Lectures - Things geeks should know about &amp;raquo; Blog Archive   &amp;raquo;  Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#6831580</link><pubDate>Sat, 22 Dec 2007 04:17:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6831580</guid><dc:creator>Geek Lectures - Things geeks should know about » Blog Archive   »  Playing with Linq grouping: GroupByMany ?</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://geeklectures.info/2007/12/21/playing-with-linq-grouping-groupbymany/"&gt;http://geeklectures.info/2007/12/21/playing-with-linq-grouping-groupbymany/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#7015667</link><pubDate>Mon, 07 Jan 2008 17:21:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7015667</guid><dc:creator>Frans Bouma</dc:creator><description>&lt;p&gt;I ran the linq query posted above using RTM linq to sql, but it results in a LOT of queries. This is logical: the main GROUP BY query ran on the DB can't contain 'City' in the projection list unless it's in the group by clause as well. So this isn't fetched. The nested group by requires 'City' so this is fetched PER CUSTOMER from the db. &lt;/p&gt;
&lt;p&gt;Instead, you should group the customers on Country AND City using an anonymous type. Though the nested group by then becomes more difficult at first glance.&lt;/p&gt;
&lt;p&gt;Linq to Sql can't merge parent/child resultsets inside a projection at runtime, so you won't get this efficiently using Linq to Sql in its current state. &lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#7039804</link><pubDate>Wed, 09 Jan 2008 15:08:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7039804</guid><dc:creator>Mitsu</dc:creator><description>&lt;p&gt;I do not understand.&lt;/p&gt;
&lt;p&gt;The whole grouping stuff is not running against Linq to Sql but Linq to object. This sample is only working in memory but I am using a Linq to Sql query to populate my collection.&lt;/p&gt;
&lt;p&gt;I have just checked again but only one sql query is executed.&lt;/p&gt;
&lt;p&gt;After 'q.ToList()', all the grouping stuff is not running Linq to Sql anymore.&lt;/p&gt;
&lt;p&gt;Regarding your comment, you are right, the group can not contain city but I am not working on the group ! I am using the group to populate the children.&lt;/p&gt;
&lt;p&gt;It's a Linq option that allows you to easilly retrieve the items of the group.&lt;/p&gt;
&lt;p&gt;g.Key contains the result of one item of the 'group by' (not containing city or any other field anymore).&lt;/p&gt;
&lt;p&gt;But g is a new IEnumerable&amp;lt;Customer&amp;gt; and g.ToList() gives you back all the customers of the group (you must consider it as a new Linq query).&lt;/p&gt;
&lt;p&gt;Mitsu&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#7047147</link><pubDate>Thu, 10 Jan 2008 03:21:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7047147</guid><dc:creator>Michael L. Harges</dc:creator><description>&lt;p&gt;Wow, this is a very timely and informative post. &amp;nbsp;I work on a product that was built pre-Linq that has a GetTree method that builds a hierarchy of TreeGroup objects that look very similar to your GroupResult class. &amp;nbsp;I was wondering this past weekend how I could accomplish the same thing in Linq and your post showed me exactly what I need to do. &amp;nbsp;Thanks!&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#7118434</link><pubDate>Tue, 15 Jan 2008 17:55:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7118434</guid><dc:creator>J</dc:creator><description>&lt;p&gt;Can anyone convert this to VB? &amp;nbsp;I'm having trouble converting the lambda function correctly (I know VB uses the Function keyword, but I'm not sure how to use it in the context of this function. &amp;nbsp;Any ideas?&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#7243831</link><pubDate>Fri, 25 Jan 2008 21:12:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7243831</guid><dc:creator>Jeremy Holt</dc:creator><description>&lt;p&gt;Hi &lt;/p&gt;
&lt;p&gt;How would you write this extremely simple SQL as LINQ?&lt;/p&gt;
&lt;p&gt;Surely I don't have to write inner loops etc.&lt;/p&gt;
&lt;p&gt;SELECT Commodity, Grade, SUM(Quantity) Quantity&lt;/p&gt;
&lt;p&gt;FROM Contacts&lt;/p&gt;
&lt;p&gt;GROUP BY Commodity, Grade&lt;/p&gt;
&lt;p&gt;RESULTS:&lt;/p&gt;
&lt;p&gt;Commodity	Grade	Quantity&lt;/p&gt;
&lt;p&gt;Arg 2002	40/50	-352.20&lt;/p&gt;
&lt;p&gt;Arg 2002	40/80	-3.00&lt;/p&gt;
&lt;p&gt;Arg 2002	50/80	100.00&lt;/p&gt;
&lt;p&gt;Arg 2004	38/50	-100.00&lt;/p&gt;
&lt;p&gt;Arg 2004	60/70	0.00&lt;/p&gt;
&lt;p&gt;Many thanks&lt;/p&gt;
&lt;p&gt;Jeremy&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#7258315</link><pubDate>Sat, 26 Jan 2008 20:34:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7258315</guid><dc:creator>mitsu</dc:creator><description>&lt;p&gt;Hi Jeremy,&lt;/p&gt;
&lt;p&gt;Try something like:&lt;/p&gt;
&lt;p&gt;var q =&lt;/p&gt;
&lt;p&gt; &amp;nbsp;from c in Commodity&lt;/p&gt;
&lt;p&gt; &amp;nbsp;group c by new {c.Commodity, c.Grade } into g&lt;/p&gt;
&lt;p&gt; &amp;nbsp;select new {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;g.Key.Commodity,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;g.Key.Grade,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Quantity = g.Sum(c =&amp;gt; c.Quantity) }&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#7264998</link><pubDate>Sun, 27 Jan 2008 15:31:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7264998</guid><dc:creator>Jeremy Holt</dc:creator><description>&lt;p&gt;Hi Mitsu,&lt;/p&gt;
&lt;p&gt;That was great - many thanks&lt;/p&gt;
&lt;p&gt;Jeremy&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#7265110</link><pubDate>Sun, 27 Jan 2008 16:06:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7265110</guid><dc:creator>Jeremy Holt</dc:creator><description>&lt;p&gt;Mitsu,&lt;/p&gt;
&lt;p&gt;I just changed it into VB and have come up with an odd problem:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim db As New AtrbeDataContext&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim funcQuantity = Function(x As ContractDetail) If(x.Contract.SellerID = 653, -x.Quantity, x.Quantity)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim qry = From c In db.ContractDetails _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Where (c.Contract.CommodityGroupID = 12 And c.ShippedStatus = 0 And c.Contract.Status = 0 And c.Contract.SellerID = 653) Or _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(c.Contract.CommodityGroupID = 12 And c.ShippedStatus = 0 And c.Contract.Status = 0 And c.Contract.BuyerID = 653) _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Group c By Commodity = c.Contract.Commodity, Grade = c.Grade Into g = Group _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Select Commodity, _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Grade, _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Quantity = g.Sum(Function(x As ContractDetail) If(x.Contract.SellerID = 653, -x.Quantity, x.Quantity)) _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Order By Commodity&lt;/p&gt;
&lt;p&gt;This works fine and gives the expected results. However, if I replace the g.Sum(....) with funcQuantity (which of course is identical) the query fails with a NotSupportedException - &amp;quot;Unsupported overload used for query operator 'Sum'.&lt;/p&gt;
&lt;p&gt;Any idea why this would be?&lt;/p&gt;
&lt;p&gt;Jeremy&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#7268719</link><pubDate>Sun, 27 Jan 2008 20:28:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7268719</guid><dc:creator>mitsu</dc:creator><description>&lt;p&gt;Ok,&lt;/p&gt;
&lt;p&gt;You must understand that Linq to Sql is analyzing the code (an expression tree) to translate it to a sql query. So Linq to Sql is only recognizing what Linq defines (actually, Linq to sql recognizes a subset of Linq methods). Your query fails here because funcQuantity can not be translated into slq by Linq to Sql.&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#7289459</link><pubDate>Mon, 28 Jan 2008 19:08:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7289459</guid><dc:creator>Ryan Versaw</dc:creator><description>&lt;p&gt;Depending on what you're using this for, it can be quite useful to strongly type your results. Keep in mind that this only works for a single Key type (just as the solution above does). It only takes a few small changes to do so: (hopefully this is displayed well...)&lt;/p&gt;
&lt;p&gt;public class GroupResult&amp;lt;TKey, TItem&amp;gt;&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; public TKey Key { get; set; }&lt;/p&gt;
&lt;p&gt; public int Count { get; set; }&lt;/p&gt;
&lt;p&gt; public IEnumerable&amp;lt;TItem&amp;gt; Items { get; set; }&lt;/p&gt;
&lt;p&gt; public IEnumerable&amp;lt;GroupResult&amp;lt;TKey, TItem&amp;gt;&amp;gt; SubGroups { get; set; }&lt;/p&gt;
&lt;p&gt; public override string ToString()&lt;/p&gt;
&lt;p&gt; {&lt;/p&gt;
&lt;p&gt; &amp;nbsp;return string.Format(&amp;quot;{0} ({1})&amp;quot;, Key, Count);&lt;/p&gt;
&lt;p&gt; }&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;public static class MyEnumerableExtensions&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; public static IEnumerable&amp;lt;GroupResult&amp;lt;TKey, TElement&amp;gt;&amp;gt; GroupByMany&amp;lt;TKey, TElement&amp;gt;(&lt;/p&gt;
&lt;p&gt; &amp;nbsp;this IEnumerable&amp;lt;TElement&amp;gt; elements, params Func&amp;lt;TElement, TKey&amp;gt;[] groupSelectors)&lt;/p&gt;
&lt;p&gt; {&lt;/p&gt;
&lt;p&gt; &amp;nbsp;if (groupSelectors.Length &amp;gt; 0)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; var selector = groupSelectors.First();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; //reduce the list recursively until zero&lt;/p&gt;
&lt;p&gt; &amp;nbsp; var nextSelectors = groupSelectors.Skip(1).ToArray();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; return&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;elements.GroupBy(selector).Select(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; g =&amp;gt; new GroupResult&amp;lt;TKey, TElement&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;Key = g.Key,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;Count = g.Count(),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;Items = g,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;SubGroups = g.GroupByMany(nextSelectors)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; });&lt;/p&gt;
&lt;p&gt; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp;else&lt;/p&gt;
&lt;p&gt; &amp;nbsp; return null;&lt;/p&gt;
&lt;p&gt; }&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#7290582</link><pubDate>Mon, 28 Jan 2008 20:40:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7290582</guid><dc:creator>Ryan Versaw</dc:creator><description>&lt;p&gt;After re-reading a little of your post, I see you mentioned that xaml does not support generic types. I suppose my previous code probably won't work for anyone using this for WPF, but for others it might be useful.&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#7302619</link><pubDate>Tue, 29 Jan 2008 12:43:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7302619</guid><dc:creator>mitsu</dc:creator><description>&lt;p&gt;Hi Ryan,&lt;/p&gt;
&lt;p&gt;Yes, xaml does not support generic types. Of course WPF does !! What you just cannot do is using the type name inside the xaml syntax.&lt;/p&gt;
&lt;p&gt;Regarding your interesting proposition, it seems that there is a problem. In your solution TKey is inferred from 'params Func&amp;lt;TElement, TKey&amp;gt;[] groupSelectors'. This means that all the group definitions are returning the same type. So you could write:&lt;/p&gt;
&lt;p&gt;q.GroupByMany(c =&amp;gt; c.Country, c =&amp;gt; c.City) because Country and City are both strings but you could not write &lt;/p&gt;
&lt;p&gt;q.GroupByMany(c =&amp;gt; c.Country, c =&amp;gt; c.DateProperty)&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#7493797</link><pubDate>Wed, 06 Feb 2008 19:48:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7493797</guid><dc:creator>Shawn</dc:creator><description>&lt;p&gt;I've been impressed by this solution but I am trying to understand how it could be made to allow a user to select one of the sorting fields using something like a combobox. Any ideas?&lt;/p&gt;
&lt;p&gt;var result = customers.GroupByMany(c =&amp;gt; c.GetProperty(ComboBox1.SelectedValue), c =&amp;gt; &amp;quot;City&amp;quot;);&lt;/p&gt;
</description></item><item><title>Linq GroupByMany dynamically</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#7500585</link><pubDate>Thu, 07 Feb 2008 02:04:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7500585</guid><dc:creator>Mitsu's blog</dc:creator><description>&lt;p&gt;Shawn asked me in my last post about GroupByMany how to use it dynamically. The answer is not easy. So&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#7500727</link><pubDate>Thu, 07 Feb 2008 02:12:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7500727</guid><dc:creator>mitsu</dc:creator><description>&lt;p&gt;Hi Shawn,&lt;/p&gt;
&lt;p&gt;Here is a solution: &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/mitsu/archive/2008/02/07/linq-groupbymany-dynamically.aspx"&gt;http://blogs.msdn.com/mitsu/archive/2008/02/07/linq-groupbymany-dynamically.aspx&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>Linq GroupByMany dynamically</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#7500775</link><pubDate>Thu, 07 Feb 2008 02:14:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7500775</guid><dc:creator>Noticias externas</dc:creator><description>&lt;p&gt;Shawn asked me in my last post about GroupByMany how to use it dynamically. The answer is not easy. So&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#7518292</link><pubDate>Thu, 07 Feb 2008 18:21:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7518292</guid><dc:creator>Shawn</dc:creator><description>&lt;p&gt;Wow Mitsu, Thank you so much for your post. I've found both to be very enlightening and informative. As I learn more about LINQ and Lambda expressions, &amp;nbsp;articles like these really showcase the power behind these new features and what is now possible. Thanks again. &lt;/p&gt;
&lt;p&gt;Shawn&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#7537696</link><pubDate>Fri, 08 Feb 2008 12:40:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7537696</guid><dc:creator>Dharmender</dc:creator><description>&lt;p&gt;Can u opls let me know the nested grouping of multiple level with this no tree view involved instead an expeneder showing the groupin n subgrouping &lt;/p&gt;
</description></item><item><title>LINQ的分组聚合技术</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#8350666</link><pubDate>Wed, 02 Apr 2008 13:22:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8350666</guid><dc:creator>墙头草</dc:creator><description>&lt;p&gt;很大程度上来讲，LINQ的工作方式很像SQL。查询源定义、join、select和where子句都是相当标准的，而Group/By/Into子句&lt;/p&gt;
&lt;p&gt;则正是我们这里要仔细说明的。SQL总是返回矩阵式数据...&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#8840894</link><pubDate>Thu, 07 Aug 2008 13:52:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8840894</guid><dc:creator>Soyka</dc:creator><description>&lt;p&gt;Thanks for the article! It helped me resolve a problem I was stuck with for a whole day! Keep up the good work..&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#8841050</link><pubDate>Thu, 07 Aug 2008 16:32:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8841050</guid><dc:creator>mitsu</dc:creator><description>&lt;p&gt;You're welcome. I am happy to see people using it.&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#9242889</link><pubDate>Sat, 20 Dec 2008 00:29:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9242889</guid><dc:creator>Leonardo</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I am trying to do dynamic subgroups on a xceed query with linq.&lt;/p&gt;
&lt;p&gt;All is working fine,my only problem is like to find a way to dynamic to build the linq query.&lt;/p&gt;
&lt;p&gt;Code:&lt;/p&gt;
&lt;p&gt;private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (e.NewValue is COP.GUI.Model.VMFund)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var activeFund = e.NewValue as COP.GUI.Model.VMFund;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//Populate the FundDetails collection with all the funds from activeFund.&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var NewData = activeFund.FundDetails.ToList();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//GroupByMany allows you to define a list of subgroups in a single call.&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//Dynamic solution&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string dealer = &amp;quot;DealerName&amp;quot;;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string portfolio = &amp;quot;Portfolio&amp;quot;;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string ticker = &amp;quot;Ticker&amp;quot;;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var resultDealerGroup = NewData.GroupByMany(dealer, portfolio, ticker);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var resultDealer = resultDealerGroup.Select(t =&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;new&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DealerName = t.Key.ToString(),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IM = (from d in t.Items as IEnumerable&amp;lt;COP.GUI.MT.Proxy.FundDealer.FundDealerDetailRow&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select d.IM).Sum(),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;VM = (from d in t.Items as IEnumerable&amp;lt;COP.GUI.MT.Proxy.FundDealer.FundDealerDetailRow&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select d.VM).Sum(),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Notional = (from d in t.Items as IEnumerable&amp;lt;COP.GUI.MT.Proxy.FundDealer.FundDealerDetailRow&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select d.Notional).Sum(),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Trades = t.Count,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Portfolio = from d in t.SubGroups as IEnumerable&amp;lt;GroupResult&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select new&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Portfolio = d.Key.ToString(),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IM = (d.Items as&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IEnumerable&amp;lt;COP.GUI.MT.Proxy.FundDealer.FundDealerDetailRow&amp;gt;).Select(g =&amp;gt; g.IM).Sum(),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;VM = (d.Items as&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IEnumerable&amp;lt;COP.GUI.MT.Proxy.FundDealer.FundDealerDetailRow&amp;gt;).Select(g =&amp;gt; g.VM).Sum(),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Notional = (d.Items as&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IEnumerable&amp;lt;COP.GUI.MT.Proxy.FundDealer.FundDealerDetailRow&amp;gt;).Select(g =&amp;gt; g.VM).Sum(),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Trades = d.Count,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ticker = from s in d.SubGroups as IEnumerable&amp;lt;GroupResult&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select new&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Ticker = d.Key.ToString(),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IM = (s.Items as&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IEnumerable&amp;lt;COP.GUI.MT.Proxy.FundDealer.FundDealerDetailRow&amp;gt;).Select(g =&amp;gt; g.IM).Sum(),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; VM = (s.Items as&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IEnumerable&amp;lt;COP.GUI.MT.Proxy.FundDealer.FundDealerDetailRow&amp;gt;).Select(g =&amp;gt; g.VM).Sum(),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Notional = (s.Items as&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IEnumerable&amp;lt;COP.GUI.MT.Proxy.FundDealer.FundDealerDetailRow&amp;gt;).Select(g =&amp;gt; g.VM).Sum(),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Trades = s.Count&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;});&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var dgCollView = this.FindResource(&amp;quot;dgViewSource&amp;quot;) as DataGridCollectionViewSource;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dgCollView.Source = resultDealer;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;tradesGrid.ItemsSource = dgCollView.View; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;Is working correctly but the user must to select from a menu with checkboxes the subgroups like dealer and portfolio and Ticker&lt;/p&gt;
&lt;p&gt;An iodea about like do do dynamic te code of the linq query depending of user chooise.???!!!&lt;/p&gt;
&lt;p&gt;Thanks in advance&lt;/p&gt;
&lt;p&gt;Leonardo&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#9529613</link><pubDate>Thu, 02 Apr 2009 22:43:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9529613</guid><dc:creator>Steve</dc:creator><description>&lt;p&gt;Thanks for the post!&lt;/p&gt;
&lt;p&gt;Very informative&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#9618698</link><pubDate>Fri, 15 May 2009 18:13:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9618698</guid><dc:creator>jhigaki</dc:creator><description>&lt;p&gt;Hey mitsu and all the other folks... a question regarding this expression&lt;/p&gt;
&lt;p&gt;/****************************************/&lt;/p&gt;
&lt;p&gt;var q =&lt;/p&gt;
&lt;p&gt; from c in Commodity&lt;/p&gt;
&lt;p&gt; group c by new {c.Commodity, c.Grade } into g&lt;/p&gt;
&lt;p&gt; select new {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; g.Key.Commodity,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; g.Key.Grade,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; Quantity = g.Sum(c =&amp;gt; c.Quantity) }&lt;/p&gt;
&lt;p&gt;/****************************************/&lt;/p&gt;
&lt;p&gt;Here the grouping criteria is an anonymous type {c.Commodity, c.Grade }&lt;/p&gt;
&lt;p&gt;I need it to be a DEFINED TYPE as &lt;/p&gt;
&lt;p&gt;public class GroupingCriteria &lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public string commodity;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public string grade;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;I've tried so far coding the Equals and CompareTo from implementing &lt;/p&gt;
&lt;p&gt;IEquatable&amp;lt;GroupingCriteria&amp;gt; and IComparable&amp;lt;GroupingCriteria&amp;gt; but it doesn't seem to work.&lt;/p&gt;
&lt;p&gt;I need this because Dotfuscator CE won't work with anonymous types expressions.&lt;/p&gt;
&lt;p&gt;Any ideas?&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#9623493</link><pubDate>Sat, 16 May 2009 22:03:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9623493</guid><dc:creator>Mitsu</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Did you try using properties instead of just fields ?&lt;/p&gt;
&lt;p&gt;public class GroupingCriteria &lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; public string commodity {get; set;};&lt;/p&gt;
&lt;p&gt; public string grade {get; set;};&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#9809928</link><pubDate>Tue, 30 Jun 2009 21:59:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9809928</guid><dc:creator>Polo H</dc:creator><description>&lt;p&gt;Can you help me understand or point me in the right direction to solve my issue? I’m trying to subgroup a Datatable(all I am given) using LINQ. I am trying to go several layers deep(5).&lt;/p&gt;
&lt;p&gt;I have tried several things but everything falls apart after a few levels. I’m sure I just don’t understand it that well yet. I have tried:&lt;/p&gt;
&lt;p&gt;var query = from nRow in newDT2.AsEnumerable()&lt;/p&gt;
&lt;p&gt;group nRow by nRow.Field(”agency_group”) into agency_group&lt;/p&gt;
&lt;p&gt;select new&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;ag = agency_group.AsEnumerable(),&lt;/p&gt;
&lt;p&gt;agK = agency_group.Key,&lt;/p&gt;
&lt;p&gt;agency_names =&lt;/p&gt;
&lt;p&gt;from agency_names in agency_group&lt;/p&gt;
&lt;p&gt;group agency_names by agency_names.Field(”agency_name”) into agency_names_group&lt;/p&gt;
&lt;p&gt;select new&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;an = agency_names_group.AsEnumerable(),&lt;/p&gt;
&lt;p&gt;anK = agency_names_group.Key,&lt;/p&gt;
&lt;p&gt;div_depts =&lt;/p&gt;
&lt;p&gt;from div_depts in agency_names_group&lt;/p&gt;
&lt;p&gt;group div_depts by div_depts.Field(”div_dept”) into div_depts_group&lt;/p&gt;
&lt;p&gt;select new&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;dd = div_depts_group.AsEnumerable(),&lt;/p&gt;
&lt;p&gt;ddK = div_depts_group.Key,&lt;/p&gt;
&lt;p&gt;unit_sections =&lt;/p&gt;
&lt;p&gt;from unit_section in div_depts_group&lt;/p&gt;
&lt;p&gt;group unit_section by unit_section.Field(”unit_section”) into unit_section_groups&lt;/p&gt;
&lt;p&gt;select new&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;us = unit_section_groups.AsEnumerable(),&lt;/p&gt;
&lt;p&gt;usK = unit_section_groups.Key,&lt;/p&gt;
&lt;p&gt;group_unit_req =&lt;/p&gt;
&lt;p&gt;from gur in unit_section_groups&lt;/p&gt;
&lt;p&gt;group gur by gur.Field(”group_unit_requirement”)&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;};&lt;/p&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;p&gt;var query = from nRow in newDT.AsEnumerable()&lt;/p&gt;
&lt;p&gt;group nRow by nRow.Field(”agency_group”) into agency_group&lt;/p&gt;
&lt;p&gt;from agency_name in&lt;/p&gt;
&lt;p&gt;(from nRow in agency_group&lt;/p&gt;
&lt;p&gt;group nRow by nRow.Field(”agency_name”) into agency_name_group&lt;/p&gt;
&lt;p&gt;from division_name in&lt;/p&gt;
&lt;p&gt;(from nRow in agency_name_group&lt;/p&gt;
&lt;p&gt;group nRow by nRow.Field(”div_dept”))&lt;/p&gt;
&lt;p&gt;group division_name by agency_name_group)&lt;/p&gt;
&lt;p&gt;group agency_name by agency_group;&lt;/p&gt;
&lt;p&gt;But something just isn’t working for me. I’ve looked all over and can’t find anything that goes that deep. Any help you can provide is greatly appreciate.&lt;/p&gt;
&lt;p&gt;Thanks for your time.&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#9810014</link><pubDate>Tue, 30 Jun 2009 23:37:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9810014</guid><dc:creator>Mitsu</dc:creator><description>&lt;p&gt;Hi Polo,&lt;/p&gt;
&lt;p&gt;Hard to say, could you send me your sample at mitsufu@microsoft.com ?&lt;/p&gt;
</description></item><item><title>Excellent</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#9872036</link><pubDate>Mon, 17 Aug 2009 09:57:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9872036</guid><dc:creator>Steven White</dc:creator><description>&lt;p&gt;The code worked perfectly and is very useful. Thanks for publishing it. :-)&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#9896130</link><pubDate>Thu, 17 Sep 2009 04:24:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9896130</guid><dc:creator>nmducit</dc:creator><description>&lt;p&gt;I want use Group by Linq in Mvc.&lt;/p&gt;
</description></item><item><title>re: Playing with Linq grouping: GroupByMany ?</title><link>http://blogs.msdn.com/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx#9898433</link><pubDate>Wed, 23 Sep 2009 16:07:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9898433</guid><dc:creator>Alex</dc:creator><description>&lt;p&gt;Here is the VB.NET translation for whoever is wondering:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Public Class GroupResult&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Public Key As Object&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Public Count As Integer&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Public Items As IEnumerable&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Public SubGroups As IEnumerable(Of GroupResult)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Public Overrides Function ToString() As String&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Return String.Format(&amp;quot;{0} ({1})&amp;quot;, Key, Count)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End Function&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;End Class&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Module Extensions&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;Extension()&amp;gt; _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Public Function GroupByMany(Of TElement)(ByRef elements As IEnumerable(Of TElement), ByVal ParamArray groupSelectors As Func(Of TElement, Object)()) As IEnumerable(Of GroupResult)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If (groupSelectors.Length &amp;gt; 0) Then&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim selector = groupSelectors.First()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim nextSelectors = groupSelectors.Skip(1).ToArray()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Return elements.GroupBy(selector).Select(Function(g) New GroupResult With {.Key = g.Key, .Count = g.Count(), .Items = g, .SubGroups = g.GroupByMany(nextSelectors)})&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Else&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Return Nothing&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End If&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End Function&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;End Module&lt;/p&gt;
</description></item></channel></rss>