2
我試圖將選擇查詢轉換爲Linq查詢,非常感謝任何幫助。將選擇語句轉換爲Linq查詢
SQL查詢
SELECT Orders.CustomerID, Orders.OrderID, Link_OrderProduct.LinkID AS Link_OrderProduct, Garages.GarageID, Products.ProductID, Garages.GarageName,VehicleDetails.Registration, Link_OrderProduct.FittingDate, Products.Brand, Products.TyreModel, Link_OrderProduct.ProductQuantity,
Products.ProductUnitSalePrice, Link_OrderProduct.TotalProductSaleCost, Link_OrderProduct.ReferralFee
FROM Link_OrderProduct INNER JOIN
Orders ON Link_OrderProduct.OrderID = Orders.OrderID INNER JOIN
Products ON Link_OrderProduct.ProductID = Products.ProductID INNER JOIN
Customers ON Orders.CustomerID = Customers.CustomerID INNER JOIN
VehicleDetails ON Customers.CustomerID = VehicleDetails.CustomerID INNER JOIN
Suppliers ON Products.SupplierID = Suppliers.SupplierID INNER JOIN
Link_GarageSupplier INNER JOIN
Garages ON Link_GarageSupplier.GarageID = Garages.GarageID ON Suppliers.SupplierID = Link_GarageSupplier.SupplierID
WHERE (Orders.Paid IS NULL) AND (Link_OrderProduct.Cancelled IS NULL)
這是我使用LINQ
var query = from Link_OrderProduct in dbcontext.Link_OrderProduct
join Order in dbcontext.Orders on Link_OrderProduct.LinkID equals Order.OrderID
join Products in dbcontext.Products on Link_OrderProduct.LinkID equals Products.ProductID
join Customers in dbcontext.Orders on Order.CustomerID equals Customers.CustomerID
join VehicleDetails in dbcontext.Customers on Customers.CustomerID equals VehicleDetails.CustomerID
join Suppliers in dbcontext.Products on Products.SupplierID equals Suppliers.SupplierID
//where d.UserID == userID
select Order;
在dbcontext.Link_GarageSupplier加入LGS上lgs.SupplierId等於Suppliers.SupplierID參加研討會在Garages.GarageID dbcontext.Garages等於lgs.GarageID –
也可以使用一些工具(如[linqpad](http://www.linqpad.net/))將您的sql代碼轉換爲linq代碼 –