我收到错误
类型的例外 发生了'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' System.Core.dll但未在用户代码中处理 信息:'object'不包含'CategoryId'的定义
下面是我的代码
dynamic product = (from prod in EntityInitializer.inventoryContext.Products
join sCat in EntityInitializer.inventoryContext.SubCategories on prod.SubCatID equals sCat.SubCategoryId
join vat in EntityInitializer.inventoryContext.VATs on prod.VatID equals vat.VatId
where prod.ProdID == proid && !prod.IsDelete
select new
{
ProductId = prod.ProdID,
CategoryId = sCat.CategoryId,
SubCategoryID = prod.SubCatID,
ProdName = prod.ProdName,
Make = prod.Make,
Finish = prod.ProdFinish,
Price = prod.Price,
Vatid=prod.VatID,
VatValue=vat.VatValue,
Unit = prod.ProdUnit,
Width = prod.ProdWidth,
Depth = prod.ProdDepth,
Height = prod.ProdHeight,
Inch = prod.ProdInch,
ImageURL = prod.ProdImage
}).FirstOrDefault();
我想从产品检索 CategoryId ,产品包含您可以在下面附加的图片中轻松找到的所有记录。
答案 0 :(得分:1)
尝试像这样访问您的媒体资源
product.GetType().GetProperty("CategoryId").GetValue(product, null);