© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
1 reply
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
Client vs. Server Evaluation - EF Core
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

❔ Unsupported method exception, how do I fix it?
C#CC# / help
4y ago
✅ Is throwing and catching an exception in an UnmanagedCallersOnly method valid?
C#CC# / help
9mo ago
How can I work around this exception?
C#CC# / help
3y ago
✅ How can i fix this?
C#CC# / help
6mo ago