LINQ中不支持指定的类型成员
TotalPrice
实体。仅初始化器,实体成员和实体导航 属性。
public JsonResult GetAllProducts()
{
db.Configuration.LazyLoadingEnabled = false; // if your table is relational, contain foreign key
List<ProductDTO> products = db.Products.Select(p => new ProductDTO
{
ProductID = p.ProductID,
ProductName = p.ProductName,
ProductCategory = p.Category.CategoryName,
UnitOfMeasure = p.UnitOfMeasure,
UnitPrice = p.UnitPrice,
UnitsInStock = p.UnitsInStock,
TotalPrice = (p.TotalPrice),
0,
UnitsOnOrder = p.UnitsOnOrder,
IntroductionDate = p.IntroductionDate,
DateCreated = p.DateCreated
}).ToList();
return Json(products, JsonRequestBehavior.AllowGet);
}