Sql to Linq Sum operations RRS feed

  • Question

  • My SQL looks like this:
    SELECT     SUM(tblBookOrders.Ordered - tblBookOrders.Received) AS Ordered
    FROM         tblBookOrders INNER JOIN
                          tblRequisitions ON tblBookOrders.RequisitionUID = tblRequisitions.RequisitionUID
    WHERE     (tblRequisitions.CampusID = '011') AND (tblBookOrders.ISBN = '0030369428') 
    AND (tblBookOrders.Status <> 'Denied') AND (tblBookOrders.Status <> 'Complete')

    I have used linqPad to create this:

    (From bo in tblBookOrders _
    join req in tblRequisitions on bo.RequisitionUID equals req.RequisitionUID _
    where bo.RequisitionUID = 3847 ANd req.CampusID = "011" and bo.ISBN = "0030369428" _
    select (bo.Ordered - bo.Received))
    I am not sure this linq to sql statement is going to give me the same result which is to sum...

    Does this look right or wrong?
    Thursday, March 18, 2010 3:09 PM


  • Hi Warren,

    I noticed that you LINQ version does not have some of the where conditions. Apart from that, if you use .Sum() after your query, the results (and even TSQL) would be same.

    var ordered =
    ( ....your linq query... ).Sum();


    Syed Mehroz Alam
    My Blog | My Articles
    Thursday, March 18, 2010 5:47 PM