LINQ to Entities不支持指定的类型成员'TotalPrice'

时间:2019-08-21 23:57:45

标签: entity-framework asp.net-mvc-5

  

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

0 个答案:

没有答案