且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Linq to SQL相当于SUM GROUP BY SQL语句

更新时间:2022-06-23 05:32:56

我仍在学习LINQ但这似乎工作

I'm still learning LINQ but this seems to work

var result = from t1 in table1
             from t2 in table2
             where t1.key == t2.key && DateTime.Parse("2010-02-01") <= t1.trndate && t1.trndate <= DateTime.Parse("2010-02-28")
             group new {t1,t2} by t1.vat into g
             select new { vat = g.Key, sum = g.Sum(p => p.t1.QTY*p.t2.FLG01 + p.t1.QTY*p.t2.FLG04)};

我希望能很好地转换为LINQ to SQL,因为我只在对象上试过它。

I hope in translates well to LINQ to SQL because I only tried it on objects.