求助LinQ语句C# codevar q from p in db.Products group p by p.CategoryID into g select new { g.Key,
求助LinQ语句
C# code
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() };