1

I am facing EntityCommandException when I try to print out LINQ results. This is my code:

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);
}

The exception is at the foreach line. If in the foreach loop I print Console.Write(co.counter);, the exception doesn't show up.

ekad
  • 14,436
  • 26
  • 44
  • 46
  • Can you post some details about the exception ? – Bas Aug 14 '12 at 08:17
  • I have this in InnerException : {"Unknown column 'GroupBy1.K2' in 'field list'"} – user1412042 Aug 14 '12 at 08:25
  • The problem disappears if I remove from the LINQ code the Count() functions ex. : 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 Thanks @BasBrekelmans select new { name= g.Key.name } ; – user1412042 Aug 14 '12 at 08:38

0 Answers0