Cannot be translated into a LINQ to Entities store expression

后端 未结 2 854
旧时难觅i
旧时难觅i 2020-12-20 16:23

I am relatively new to LINQ-to-Entities, but use LINQ-to-SQL a lot.

I am using Visual Studio 2013 with Entity Framework 6 and MVC 5.

The biggest difference b

相关标签:
2条回答
  • 2020-12-20 17:10

    I know I'm a little late to the party but for anyone doing a Google search:

    I had this problem and it turns out the class the DbFunctionAttribute is on has to have the same namespace as the edmx schema.

    So in this case either change the edmx schema namespace to BillYeagerDB,
    or change the EdmxExtensionMethods namespace to BillYeagerModel

    0 讨论(0)
  • 2020-12-20 17:12

    try to rewrite your select method to this:

    var restaurants = await DbContext.Restaurants.GroupBy(g => g).ToListAsync();
    return restaurants.Select(s =>
      new RestaurantList()
      {
        Name = s.Key.Name,
        City = s.Key.City,
        Phone = s.Key.Phone,
        AvgRating = s.Average(a => Convert.ToDecimal(a.Rating.RatingValue)),
        NbrOfPeopleRating = s.Distinct().Count(c => Convert.ToBoolean(c.RatingId)),
        Id = s.Key.Id
      });
    
    0 讨论(0)
提交回复
热议问题