簡體   English   中英

對象不包含“屬性”的定義

[英]object does not contain a definition for “Properties”

我收到一個錯誤

System.Core.dll中發生類型'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException'的異常,但未在用戶代碼中處理。其他信息:'對象'不包含'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

嘗試像這樣訪問您的財產

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM