Linq上的EntityCommandException具有group by和count

时间:2012-08-14 08:16:42

标签: c# linq join linq-group

当我尝试打印出LINQ结果时,我正面临EntityCommandException。这是我的代码:

var contacts = from c in db.mydata
               join r in db.contacts on c.user equals r.user 
               group c by new { c.user, r.name }
               into g
               orderby g.Count() descending
               select new { name= g.Key.name , counter = g.Count() } ;

foreach (var co in contacts )
{
    Console.Write(co.name);
}

例外是在foreach行。如果在foreach循环中我打印Console.Write(co.counter);,则不会显示异常。

0 个答案:

没有答案