Return multiple aggregate columns in LINQ

前端 未结 4 1287
孤城傲影
孤城傲影 2020-12-06 11:25

I would like to translate the following SQL into LINQ:

SELECT
    (Select count(BidID)) as TotalBidNum,
    (Select sum(Amount)) as TotalBidVal
FROM Bids
         


        
4条回答
  •  粉色の甜心
    2020-12-06 12:10

    You could do it using the Aggregate Clause.

    Aggregate t In _dataContext.Bids
    Into TotalBidNum = Count(BidID),
         TotalBidVal = Sum(Amount)
    

    If you're using Fx4+ or an extension dll for Fx2, you could also benfit from parallelism by using

    Aggregate t In _dataContext.Bids.AsParallel
    

提交回复
热议问题