user1587381
user1587381

Reputation: 25

object does not contain a definition for "Properties"

I am getting an error

An exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in System.Core.dll but was not handled in user code Additional information: 'object' does not contain a definition for 'CategoryId'

below is my code

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();

I want to retrieve CategoryId from product and product has contain all records which you can easily find in below attached image.

https://i.sstatic.net/6athN.png

error image https://i.sstatic.net/ra0rL.png

Upvotes: 0

Views: 3508

Answers (1)

Clint
Clint

Reputation: 2793

Try to access your property like this

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

Upvotes: 3

Related Questions