I would like to translate the following SQL to LINQ:
SELECT (Select count(BidID)) as TotalBidNum, (Select sum(Amount)) as TotalBidVal FROM Bids
I tried this:
from b in _dataContext.Bids select new { TotalBidVal = b.Sum(p => p.Amount), TotalBidNum = b.Count(p => p.BidId) }
but get the error message "Bets do not contain a definition for" Amount "and cannot be found the extension method" Amount ", which takes the first argument of the type" Bids ".
How to do it in LINQ?
thanks
FINAL:
Final answer:
var ctx = _dataContext.Bids; var itemsBid = (from b in _dataContext.Bids select new { TotalBidVal = ctx.Sum(p => p.Amount), TotalBidNum = ctx.Count() }).First();
aggregate linq-to-sql
Bkahuna
source share