The specified type member 'UsersCount' is not supported in LINQ to Entities

前端 未结 2 1445
广开言路
广开言路 2020-12-21 23:45

I have such POCO entity

  public class Product : Entity

 {
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int Id { get; set; }
            


        
2条回答
  •  不思量自难忘°
    2020-12-22 00:26

    Try this instead:

       var model = _productService.GetAll().Select(p => new AdminProductViewModel
       {
          Active = p.Active,
          Id = p.Id,
          Name = p.Name,
          UsersCount = p.Orders.Count()
       }).ToList();
    

    Linq to Entities can't translate the Product.UsersCount property into sql so it gives you the error message

    The specified type member 'UsersCount' is not supported in LINQ to Entities

提交回复
热议问题