zeeshan akram

zeeshan akram

  • 1.3k
  • 325
  • 16.6k

How to resolve this problem cannot constructed in LING

Mar 3 2020 12:15 AM
Error: System.NotSupportedException: 'The entity or complex type 'ECommercedbModel.ProductDetail' cannot be constructed in a LINQ to Entities query.'
 
 
  1. public ProductViewModel GetProductByID(int ID)  
  2.         {  
  3.             ProductViewModel listprod = new ProductViewModel();  
  4.   
  5.             try  
  6.             {  
  7.                 var productsl = (from p in _db.Products  
  8.                                  where p.ProductID == ID  
  9.   
  10.                                  select new Product  
  11.                                  {  
  12.                                      PName= p.PName,  
  13.                                      PDescription= p.PDescription,  
  14.                                      Model= p.Model,  
  15.                                      Condition= p.Condition,  
  16.                                      UnitPrice=p.UnitPrice,  
  17.                                      ManificturedPrice=p.ManificturedPrice,  
  18.                                      Discount=p.Discount,  
  19.                                      UnitWeight=p.UnitWeight,  
  20.                                      UnitInStock=p.UnitInStock  
  21.                                  }).FirstOrDefault();  
  22.   
  23.                 var productD = (from pd in _db.ProductDetails  
  24.                                 join b in _db.Products on pd.ProductID equals b.ProductID  
  25.                                 where pd.ProductID == ID  
  26.                                 select new ProductDetail  
  27.                                 {  
  28.                                     ProductID =pd.ProductID,  
  29.                                     OS=pd.OS,  
  30.                                     ProcessorType=pd.ProcessorType,  
  31.                                     RAM=pd.RAM,  
  32.                                     ScreenSize=pd.ScreenSize,  
  33.                                     TouchScreen=pd.TouchScreen,  
  34.                                     BatteryLife=pd.BatteryLife,  
  35.                                     Camera=pd.Camera  
  36.                                 }).ToList();  
  37.   
  38.                 return new ProductViewModel { listProducts = productsl, listProductDetails = productD };  
  39.             }  
  40.   
  41.             catch (Exception)  
  42.             {  
  43.   
  44.                 throw;  
  45.             }  
  46.         }  

Answers (1)