当我尝试打印出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);
,则不会显示异常。