1

When I write the linq query like this, I get the error message

"System.InvalidOperationException: 'The LINQ expression 'DbSet() .GroupJoin( inner: DbSet(), outerKeySelector: d => d.Id, innerKeySelector: dc => dc.DeviceId, resultSelector: (d, dc) => new { deviceName = d.Name, cams = dc })' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.'

How should I edit the code?

var query = context.Devices
                   .GroupJoin(context.DeviceControls,
                              d => d.Id,
                              dc => dc.DeviceId,
                              (d, dc) => new
                                         {
                                             deviceName = d.Name,
                                             Cams = dc,
                                         }).ToList();
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

2

EF core with .net core 3.1 will not let you do group by unless you do it client side. You need to call var query = context.Devices.ToList() and then do your group call on the query variable. Another option, if possible, is upgrading to .net 6. I think then you can do a server side group by.

rleffler
  • 430
  • 6
  • 15
  • Thank you for answer .my problem was resolved when i did query = context.Devices.ToList() –  Feb 14 '22 at 20:11