In .Net framework I had this working query:
IEnumerable<Cars> LatestCars = await _context.Cars.Where(x => x.IsActive == true && x.IsDeleted == false)
.GroupBy(y => y.ManufacturerId)
.Select(z =>
z.OrderByDescending(k => k.ReleaseDate)
.FirstOrDefault()
)
.OrderByDescending(l => l.ReleaseDate)
.Take(5)
.ToListAsync();
This basicly gets the latest 5 cars released by distinct manufacturers.
But when I switched to .NET Core. This query is not working anymore. And I have this error when I run it:
System.InvalidOperationException: The LINQ expression '(GroupByShaperExpression:
KeySelector: (g.ManufacturerId),
ElementSelector:(EntityShaperExpression:
EntityType: Cars
ValueBufferExpression:
(ProjectionBindingExpression: EmptyProjectionMember)
IsNullable: False
)
)
.OrderByDescending(p => p.ReleaseDate)' 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 either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync().
Do you have any suggestions? Thank you.