The entity cannot be constructed in a LINQ to Entities query

前端 未结 14 2031
失恋的感觉
失恋的感觉 2020-11-21 06:04

There is an entity type called Product that is generated by entity framework. I have written this query

public IQueryable GetProdu         


        
14条回答
  •  [愿得一人]
    2020-11-21 06:49

    you can add AsEnumerable to your collection like the follow :

    public IQueryable GetProducts(int categoryID)
    {
        return from p in db.Products.AsEnumerable()
               where p.CategoryID== categoryID
               select new Product { Name = p.Name};
    }
    

提交回复
热议问题