question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nested (through navigation property) Value Conversion (enum to string) causes exception.

See original GitHub issue

From @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).

  1. Problem Query: https://hastebin.com/ugufozituy.cs
  2. ModerationActionSummary.FromEntityProjection: https://hastebin.com/ukudanudoc.cs
  3. ModerationActionEntity: https://hastebin.com/lemedabofe.cs
  4. InfractionEntity: https://hastebin.com/wihotayoyu.cs
  5. ModixContext.OnModelCreating(): https://hastebin.com/iqayacecox.cs
  6. InfractionSummary: https://hastebin.com/padakicese.cs
  7. 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:

  1. netcoreapp2.1
  2. Microsoft.EntityFrameworkCore (2.1.1)
  3. Mpgsql.EntityFrameworkCore.PostgreSQL (2.1.1)
  4. Windows 8.1 Pro
  5. Visual Studio 2017 15.7.5.

Copied from original issue: aspnet/EntityFrameworkCore#12834

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
smitpatelcommented, Aug 16, 2018

Can close this as duplicate of https://github.com/aspnet/EntityFrameworkCore/issues/13025 I am adding code to unwrap nullableExpression

1reaction
smitpatelcommented, Jul 31, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

EF Core 3 Nested Value Conversion Cannot be Translated
The crux of the issue is caused by using a nested field on a property inside the where clause; I've provided a simplified...
Read more >
Breaking changes in EF Core 6.0
Unknown enum string values in the database are not converted to the enum default when queried.
Read more >
What's New in EF Core 7.0
The document above uses a value converter to transform the collection into a comma-separated string. Vote for Json: add support for ...
Read more >
Enum HOWTO — Python 3.11.4 documentation
An Enum is a set of symbolic names bound to unique values. They are similar to global variables, but they offer a more...
Read more >
Enumeration declaration
An enumeration is a distinct type whose value is restricted to a range of values (see below for details), which may include several ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found