简体   繁体   English

连接两个表时出现 System.InvalidOperationException

[英]System.InvalidOperationException while join two table

In project i have two tables在项目中我有两张桌子

  • Restaurant (RestaurantId, Name, Adress)餐厅(RestaurantId、名称、地址)
  • RestaurantReview (ReviewId, RestaurantId, Mark) RestaurantReview(ReviewId、RestaurantId、Mark)

I want to display one restaurant and calculate its average Mark我想显示一家餐厅并计算其平均分数

var lj = (from x in _context.Restaurant
         join y in _context.RestaurantReview on x.RestaurantId equals y.RestaurantId into z
         select new
         {
              Name= x.Name,
              Total = z.Average(x => Convert.ToInt32(x.Mark))
         }).ToList();

while run this code i got error运行此代码时出现错误

System.InvalidOperationException: „Processing of the LINQ expression 'GroupJoin<Restaurant, RestaurantReview , int, <>f__AnonymousType4<string, double>>(
    outer: DbSet<Restaurant>, 
    inner: DbSet<RestaurantReview >, 
    outerKeySelector: (x) => x.RestaurantId, 
    innerKeySelector: (y) => y.RestaurantId, 
    resultSelector: (x, z) => new { 
        Name = x.Name , 
        Total = Average<RestaurantReview >(
            source: z, 
            selector: (x) => ToInt32(x.mark))
     })' by 'NavigationExpandingExpressionVisitor' failed. This may indicate either a bug or a limitation in EF Core. 

I try use other query, but every time I get the same error我尝试使用其他查询,但每次我得到同样的错误

group by missing in your code.在您的代码中缺少分组。 Add group by in linq expression在 linq 表达式中添加 group by

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM