這是我的LINQ到SQL查詢哪些工作正常,但是當我投擲並返回數據時,我得到了投射錯誤。任何一個可以幫助鑄造下面的linq查詢?
var productImages = from prod in context.seller_productinventory.AsEnumerable()
join prodImage in context.seller_productimages on prod.prdid equals prodImage.prdid
join category in context.mstr_scategory on prod.mcid equals category.CategoryID
join subcategory in context.mstr_scategory on prod.scid equals subcategory.CategoryID
select new
{
ProductId = prod.prdid,
Category = category.CategoryName,
Subcategory = subcategory.CategoryName,
Image1 = prodImage.image1Path,
Image2 = prodImage.image2Path,
Image3 = prodImage.image3Path,
Image4 = prodImage.image4Path,
ProductStatusCd = (Convert.ToInt32(prod.isAdminApproved) != 1) ? "Pending Approval" : "Approved"
};
我在下面的代碼中得到錯誤。
return (IEnumerable<ProductImageModel>) productImages.ToList();
我的模型類:
public class ProductImageModel
{
public int ProductId { get; set; }
public string Category { get; set; }
public string Subcategory { get; set; }
public string Image1 { get; set; }
public string Image2 { get; set; }
public string Image3 { get; set; }
public string Image4 { get; set; }
public string ProductStatusCd { get; set; }
}
那麼錯誤是什麼? – Dbloch
這是因爲您選擇了「匿名」類型。 – gleng