none
SQL to LINQ RRS feed

  • Question

  • Hi,

     

    I am new to ling want to the following sql into Linq.

       FROM TLA.Tanks T INNER JOIN dbo.Component C 

    ON T.ComponentID=C.ComponentID AND T.OrderLevelAlert = 1 

    INNER JOIN dbo.ControllerMaster CM 

    ON CM.SystemID=C.SystemID INNER JOIN dbo.FacilityMaster FM

    ON FM.FacilityID=CM.FacilityID INNER JOIN dbo.CustomerMaster Cust

    ON Cust.CustomerID=FM.CustomerID INNER JOIN TLA.BillingArrangement TBA

    ON TBA.SystemID=CM.SystemID INNER JOIN TLA.TankBillingArrangement BA

    ON BA.TankBillingArrangementId=TBA.BillingArrangementId INNER JOIN TLA.ProductsMaster PM

    ON PM.ProductID=T.ProductId 

     

    Thanks

     

    Thursday, January 12, 2012 11:22 AM

Answers

  • I don't see a complete SQL here. Anyway in Linq it might be as simple as:

    var data = db.Tanks.Where( t => t.OrderLevelAlert == 1);

     

    Inner joins are only serving as limiting the results who have entries in other tables as well (in case of Customers and Orders, Customers who have at least 1 order at least - IOW an exists subquery) and simply could be included like (assuming Component's entity name Components) - provided you have your database have integrity relations and/or your model:

    var data = db.Tanks.Where( t => t.OrderLevelAlert == 1 && t.Components.Any() && ... );

     

     

    Thursday, January 12, 2012 5:06 PM