0
我想將此SQL轉換爲實體框架LINQ,但不工作。Left加入實體框架
我的SQL代碼:
SELECT
s.Id,
s.OriginalPhotoBlobId,
s.PhotoBlobExtension,
ISNULL(s.ProductSkuKey, p.[Key]) as [Key],
p.Name,
ISNULL(sp.Price, 0) as [Price],
sp.PriceList_Id
FROM SKUs s
INNER JOIN Products p on p.Id = s.Product_Id
LEFT JOIN SKUPrices sp on sp.SKU_Id = s.Id
我的實體框架代碼:
var db = this.Context;
var prices = from s in db.SKUs
join p in db.Products on s.Product equals p
join sp in db.SKUPrices on s equals sp.SKU into gj
from spss in gj.DefaultIfEmpty()
select new PriceListItem
{
Id = s.Id,
BlobId = s.OriginalPhotoBlobId,
BlobExtension = s.PhotoBlobExtension,
Key = ((s.ProductSkuKey == null || s.ProductSkuKey.Trim() == string.Empty) ? p.Key : s.ProductSkuKey),
Name = p.Name,
Price = (spss == null ? default(double) : spss.Price),
};
你能解釋一下你正在試圖通過精確地轉化這個達到什麼樣的目標?例如,通過使用include,您不必使用像這樣的連接。 – 2013-05-03 14:10:36
你能解釋一下_你的工作_是什麼意思嗎? – 2013-05-03 14:34:48