下面是我的SQL查詢左外連接,並從三個表拿到三列
SELECT (((((('L' + (CONVERT(NVARCHAR(MAX), t0.Length))) + 'W') + (CONVERT(NVARCHAR(MAX), t0.Width))) +
'H') + (CONVERT(NVARCHAR(MAX), t0.Height))) + ' - ') + t0.DimUoM AS 'Dimensions'
, (((CONVERT(NVARCHAR(MAX), t0.NetWt)) + ' (') + t0.NetWtUoM) + ')' AS 'Weight'
, t0.UPCCode
, t1.DisplayBrand AS 'Brand'
, t2.ID
FROM SmartSearchNewQA.dbo.MaterialMaster AS t0
LEFT OUTER JOIN dbo.BrandConversion AS t1
ON t0.Brand = t1.SAPBrand
LEFT OUTER JOIN ClickCommerce.dbo.tblWarrantyPartReturn AS t2
ON t0.MaterialNumber = t2.PartNumber
LEFT OUTER JOIN ClickCommerce.dbo.tblWarrantyPartReturnAddress AS t3
ON t2.ReturnCode = t3.ReturnCode
WHERE t0.MaterialNumber = 'S1-326000' AND
t2.DistributorId = '00100';
正在嘗試上述查詢LINQ轉換並不能映射第二個表。請找到下面的LINQ我推導到目前爲止
from mm in ctx.MaterialMasters
join bc in ctx.BrandConversions on mm.Brand equals bc.SAPBrand into bc1
from brandConv in bc1.DefaultIfEmpty()
join wp1 in ctx.tblWarrantyPartReturns
on mm.MaterialNumber equals wp1.PartNumber into bc2
from partconv in bc2.DefaultIfEmpty()
join wp2 in ctx.tblWarrantyPartReturnAddresses
on bc2
from partconv2 in bc3.DefaultIfEmpty()
where mm.MaterialNumber == materialNumber
select new MaterialHeader
{
Brand = brandConv.DisplayBrand,
Dimensions = "L" + mm.Length + ":W" + mm.Width + ":H" + mm.Height + " - " + mm.DimUoM,
UPCCode = mm.UPCCode,
Weight = mm.NetWt + " (" + mm.NetWtUoM + ")"
})
請幫助我與LINQ查詢到達上述SQL結果。
謝謝
哎呀,該查詢是可怕的閱讀。所有這些[和]絕對無用的別名使得這個用戶充其量是充滿敵意的。然後是瘋狂的多餘的(和)。我知道你試圖將它轉移到LINQ,但你應該閱讀更多關於爲什麼這些別名是壞的。 http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/08/bad-habits-to-kick-using-table-aliases-like-a-b-c-or-t1-t2-t3.aspx –