C
C#2y ago
linqisnice

❔ I can't fix this query. It's throwing an exception.

"The LINQ expression 'date => DbSet<AccomodationInventory>()\r\n .Where(a0 => EF.Property<int?>(EntityShaperExpression: \r\n CampiconAPI.Domain.Entities.Accomodation\r\n ValueBufferExpression: \r\n ProjectionBindingExpression: EmptyProjectionMember\r\n IsNullable: False\r\n , "Id") != null && object.Equals(\r\n objA: (object)EF.Property<int?>(EntityShaperExpression: \r\n CampiconAPI.Domain.Entities.Accomodation\r\n ValueBufferExpression: \r\n ProjectionBindingExpression: EmptyProjectionMember\r\n IsNullable: False\r\n , "Id"), \r\n objB: (object)EF.Property<int?>(a0, "AccomodationId")))\r\n .Any(a0 => a0.Date.ToString() == date.Date.ToString() && a0.TotalReserved < a0.TotalInventory)' 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.",
var listingTest = await _dbContext.Listings.Where(listing =>
listing.Accomodations.Any(accommodation =>
dateRange.All(date =>
accommodation.Inventory.Any(inv =>
inv.Date.ToString() == date.Date.ToString() && inv.TotalReserved < inv.TotalInventory)))).ToListAsync();
var listingTest = await _dbContext.Listings.Where(listing =>
listing.Accomodations.Any(accommodation =>
dateRange.All(date =>
accommodation.Inventory.Any(inv =>
inv.Date.ToString() == date.Date.ToString() && inv.TotalReserved < inv.TotalInventory)))).ToListAsync();
the reason I do tostring() is because inv.Date is dateonly and date.Date is DateTime. But I've tried with both being dateonly and i still get the same error. But i cant really understand why im getting this error. I've been trying to fix it for 2 hours lol
Client vs. Server Evaluation - EF Core
Client and server evaluation of queries with Entity Framework Core
1 Reply
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server