I'm trying convert this SQL to Entity Framework LINQ, but don't working.
My SQL code:
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
My Entity Framework Code:
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),
};