-
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
HasConversion no longer supports captured Object in EF Core 9, when using projection #34956
Comments
EF Core 8.0 generate the below codes for projection in your demo. (queryContext, dataReader, resultContext, resultCoordinator) =>
{
string namelessParameter{0};
string namelessParameter{1};
namelessParameter{0} = dataReader.IsDBNull(0) ? default(string) : MyDbContext.Converter.Decrypt(dataReader.GetString(0));
namelessParameter{1} = dataReader.IsDBNull(1) ? default(string) : <>c__DisplayClass7_0.customConverter.Decrypt(dataReader.GetString(1));
return new {
One = namelessParameter{0},
Two = namelessParameter{1}
};
} directly use closured variable for
However, EF Core 9.0 generate the below codes: (queryContext, dataReader, resultContext, resultCoordinator) =>
{
string value1;
string value2;
value1 = dataReader.IsDBNull(0) ? default(string) : MyDbContext.Converter.Decrypt(dataReader.GetString(0));
value2 = dataReader.IsDBNull(1) ? default(string) : Invoke(((ValueConverter<string, string>)[LIFTABLE Constant: SqliteStringTypeMapping | Resolver: c => (RelationalTypeMapping)c.Dependencies.TypeMappingSource.FindMapping(
type: System.String,
model: c.Dependencies.Model,
elementMapping: null)].Converter).ConvertFromProviderTyped, dataReader.GetString(1));
return new {
One = value1,
Two = value2
};
} EF 9.0 uses new
Lines 2912 to 2925 in 60524c9
I think this issue have fixed in main branch already. Lines 2792 to 2802 in 931a67c
|
Thanks for the investigation @Li7ye ! @TheConstructor the fix indeed found its way to 9.0 so this should be fixed when we release. You can also try our daily build. Closing as dupe of #34760 |
As mentioned in #12205 (comment) and as requested by @roji:
When trying to update our project to EF Core 9 RC2, we encountered a NullReferenceException, were EF Core 8 did not throw one. The trouble seems to arise from the attempt to optimize a projection during query execution. If the conversion relies on a static object-instance no closure is created, and the optimization succeeds, but in all other cases it does not.
Short reproduction
Include provider and version information
EF Core version: 9.0.0-rc.2.24474.1
Database provider: I first found this using Microsoft.EntityFrameworkCore.SqlServer, but can reproduce it using Sqlite. InMemory is not affected.
Target framework: .NET 8.0
Operating system: Windows 11
IDE: Rider
The text was updated successfully, but these errors were encountered: