Nested (through navigation property) Value Conversion (enum to string) causes exception.
See original GitHub issueFrom @JakenVeina on July 28, 2018 5:52
When selecting an enum value from a related record, conversions defined for that property are not evaluated, and cause an InvalidCastException
(wrapped by an InvalidOperationException
).
- Problem Query: https://hastebin.com/ugufozituy.cs
- ModerationActionSummary.FromEntityProjection: https://hastebin.com/ukudanudoc.cs
- ModerationActionEntity: https://hastebin.com/lemedabofe.cs
- InfractionEntity: https://hastebin.com/wihotayoyu.cs
ModixContext.OnModelCreating()
: https://hastebin.com/iqayacecox.csInfractionSummary
: https://hastebin.com/padakicese.cs- Full Codebase: https://github.com/JakenVeina/MODiX/tree/efcore-issue-12834
Specifically, the Type = entity.Infraction.Type,
line in snippet 2 above is causing the following exception: https://hastebin.com/equfozunaj.
When the .Type
property is being selected from the root element in an expression, as in snippet 6 above, the value conversion works fine.
Furthermore, I can work around the error by changing
Type = entity.Infraction.Type
in snippet 2, to the following lovely expression.
Type = Enum.Parse<InfractionType>(entity.Infraction.Type.ToString())
This seems to work great. The whole query still evaluates to one SQL query. But surely, there ought to be a way to support the more sensible version of the expression.
Using:
- netcoreapp2.1
- Microsoft.EntityFrameworkCore (2.1.1)
- Mpgsql.EntityFrameworkCore.PostgreSQL (2.1.1)
- Windows 8.1 Pro
- Visual Studio 2017 15.7.5.
Copied from original issue: aspnet/EntityFrameworkCore#12834
Issue Analytics
- State:
- Created 5 years ago
- Comments:17 (13 by maintainers)
Can close this as duplicate of https://github.com/aspnet/EntityFrameworkCore/issues/13025 I am adding code to unwrap nullableExpression
Since I did not have PostgreSQL installed, I tried it with SqlServer and it worked fine, moving it here. If this repros in other providers then feel free to open an issue in EF Core repo.