对象不包含“属性”的定义

时间:2016-05-22 17:42:34

标签: c#

我收到错误

  

类型的例外   发生了'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 ,产品包含您可以在下面附加的图片中轻松找到的所有记录。

http://i.stack.imgur.com/6athN.png

错误图片   http://i.stack.imgur.com/ra0rL.png

1 个答案:

答案 0 :(得分:1)

尝试像这样访问您的媒体资源

product.GetType().GetProperty("CategoryId").GetValue(product, null);