使用Linq group by 查询 一般我们都会这样写Linq:
var result = (from si in model.table group si by si.NumCores into grp orderby grp.Key select new CoreCount { Cores = grp.Key, Count = grp.Count() }).ToList(); 正确的答案(MySql):
var result = (from si in model.table group si by si.NumCores into grp orderby grp.Key select new CoreCount { Cores = grp.FirstOrDefault().NumCores, Count = grp.Count() }).ToList();
以上在MySQL亲测有效,SQL server没有测试。。。
C# linq group by 异常 -----MySqlException: Unknown column 'GroupBy1.K1' in 'field list'