-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Projection filtering on second-level reference could not be translated #31961
Comments
This is the predicate we generate after nav expansion: .Where(c => (c.Outer.Inner != null ? new CompanyDto{
Id = c.Outer.Inner.Id,
CompanyName = c.Outer.Inner.CompanyName,
CountryId = c.Outer.Inner.CountryId,
Country = new CountryDto{
Id = c.Inner.Id,
CountryName = c.Inner.CountryName
}
}
: null).Country.CountryName == "COUNTRY") which then gets simplified to: .Where(c => ((ICountryDto)c.Outer.Inner != null ? new CountryDto{
Id = c.Inner.Id,
CountryName = c.Inner.CountryName
}
: null).CountryName == "COUNTRY") what we do is we see member access (Country) over conditional null check, and we simplify it by just leaving the member we are accessing and discarding the rest. We inject the convert because outer_conditional.Coutry is typed as ICountryDto, but the result we get from first round of optimization is typed as CoutryDto. This is what we would/should have gotten, which is perfectly trasnlatable and indeed what we produce for non-interface case: .Where(c => (c.Outer.Inner != null ? c.Inner.CountryName : null) == "COUNTRY") @clemvnt the issue you linked is indeed connected and fixes the case without interface (which was previously also broken) |
…not be translated Problem was that optimizing visitor was looking for a very specific pattern (member access over conditional), but in this scenario conditional is wrapped around Convert node. Fix is to recognize this case also, strip convert around the conditional and apply it around non-null portion instead, before applying the member access over it. Fixes #31961
…not be translated Problem was that optimizing visitor was looking for a very specific pattern (member access over conditional), but in this scenario conditional is wrapped around Convert node. Fix is to recognize this case also, strip convert around the conditional and apply it around non-null portion instead, before applying the member access over it. Fixes #31961
…not be translated Problem was that optimizing visitor was looking for a very specific pattern (member access over conditional), but in this scenario conditional is wrapped around Convert node. Fix is to recognize this case also, strip convert around the conditional and apply it around non-null portion instead, before applying the member access over it. Fixes #31961
…not be translated Problem was that optimizing visitor was looking for a very specific pattern (member access over conditional), but in this scenario conditional is wrapped around Convert node. Fix is to recognize this case also, strip convert around the conditional and apply it around non-null portion instead, before applying the member access over it. Fixes #31961
…not be translated (#31996) Problem was that optimizing visitor was looking for a very specific pattern (member access over conditional), but in this scenario conditional is wrapped around Convert node. Fix is to recognize this case also, strip convert around the conditional and apply it around non-null portion instead, before applying the member access over it. Fixes #31961
Hi,
I encounter an issue when I make a query where a filter (or sort) is apply on a property of a reference of reference (second level).
The filter is apply on a projection (the three levels are transformed into DTO).
The entities are the following :
The query is the following :
A few investigations :
m => m.Company!.CompanyName == "COMPANY"
)public CountryDto? Country { get; set; }
instead ofpublic ICountryDto? Country { get; set; }
Reproduction : https://github.com/clemvnt/efcore-projection-nested-reference
Stack trace
Include provider and version information
EF Core version: 7.0.11
Database provider: Tested with Microsoft.EntityFrameworkCore.SqlServer and Microsoft.EntityFrameworkCore.Sqlite
Target framework: NET 8.0
Operating system: Windows 11
IDE: Visual Studio 2022 17.7.1
The text was updated successfully, but these errors were encountered: