var q = from p in db.Products
group p by p.CategoryID into g
select new { g.Key, NumProducts = g.Count() };
请问这条语句怎么转换成非匿名语句
------解决方案-------------------- var q = from p in db.Products group p by p.CategoryID into g select new { g.Key, NumProducts = g.Count() }; Console.WriteLine(q.GetType().ToString());
------解决方案-------------------- var q = from p in db.Products group p by p.CategoryID into g select g; ToList();
------解决方案-------------------- 啥叫非匿名,我猜是非匿名类型。
class Result { public int Key {set;get;} public int Count {set;get;} }
var q = from p in db.Products group p by p.CategoryID into g select new Result(){ Key = g.Key, Count = g.Count() };