Error: System.NotSupportedException: 'The entity or complex type 'ECommercedbModel.ProductDetail' cannot be constructed in a LINQ to Entities query.'
- public ProductViewModel GetProductByID(int ID)
- {
- ProductViewModel listprod = new ProductViewModel();
-
- try
- {
- var productsl = (from p in _db.Products
- where p.ProductID == ID
-
- select new Product
- {
- PName= p.PName,
- PDescription= p.PDescription,
- Model= p.Model,
- Condition= p.Condition,
- UnitPrice=p.UnitPrice,
- ManificturedPrice=p.ManificturedPrice,
- Discount=p.Discount,
- UnitWeight=p.UnitWeight,
- UnitInStock=p.UnitInStock
- }).FirstOrDefault();
-
- var productD = (from pd in _db.ProductDetails
- join b in _db.Products on pd.ProductID equals b.ProductID
- where pd.ProductID == ID
- select new ProductDetail
- {
- ProductID =pd.ProductID,
- OS=pd.OS,
- ProcessorType=pd.ProcessorType,
- RAM=pd.RAM,
- ScreenSize=pd.ScreenSize,
- TouchScreen=pd.TouchScreen,
- BatteryLife=pd.BatteryLife,
- Camera=pd.Camera
- }).ToList();
-
- return new ProductViewModel { listProducts = productsl, listProductDetails = productD };
- }
-
- catch (Exception)
- {
-
- throw;
- }
- }