我不是LINQ的专家,但我想了解。如何用c语言编写这段代码(用vb编写)#
dim x=从p到db.yourclass_
其中p.fl1=cn1,p.f12=cn2
选择_
sum1=x.sum(函数(y)y.fl1),,_
sum2=x.sum(函数(y)y.fl2),,_
sum3=x.sum(函数(y)y.fl3)
我要达到的是,
选择SUM(FL1)、SUM(FL2)、SUM(FL3)
式中,fl1=cn1,fl2=cn2
The above sample found here

最佳答案

var x = from p in db.YourClass
        where p.fl1 == cn1 && p.f12 == cn2
        select p;

  var sum1 = x.Sum(y=>y.fl1),

  var sum2 = x.Sum(y=>y.fl2),

  var sum3 = x.Sum(y=>y.fl3)

编辑:在一个查询中,我认为这可以快速工作:
var x = (from p in db.YourClass

        select new
        {
         s1 = db.YourClass.Where(y=> y.fl1 == cn1 && y.f12 == cn2).Sum(y=>y.fl1),
         s2 = db.YourClass.Where(y=> y.fl1 == cn1 && y.f12 == cn2).Sum(y=>y.fl2),
         s3 = db.YourClass.Where(y=> y.fl1 == cn1 && y.f12 == cn2).Sum(y=>y.fl3)
        }).First();

 int sum1 = x.s1, sum2 = x.s2, sum3 = x.s3;

08-28 21:38