Skip to content

Enum downcasting throws on write - #490

Closed
austindrenski wants to merge 4 commits into
npgsql:devfrom
austindrenski:enum-issue
Closed

austindrenski wants to merge 4 commits into
npgsql:devfrom
austindrenski:enum-issue

Conversation

@austindrenski

@austindrenski austindrenski commented Jun 27, 2018 •

Copy link
Copy Markdown
Contributor

Work in progress

  • Adds a test to show that downcasting an enum parameter causes an exception.
  • Cleans up EnumQueryTest.cs to simplify/align with other recent query tests.

See: #489

- Status: failing
__However__, this introduces some problems. Enums used in binary
comparison operations (maybe others?) are cast to their underlying
system type in the expression tree.

So the fix in this commit is insufficient. We need to address this
from the `VisitBinary` methods, where either a custom expression
needs to be returned, or the whole comparison needs to be handled.

Otherwise, obvious looking code can't be handled. For example:

```c#
src.Where(x => x.MyInt == (int) myEnumVariable)
```
- This is a very narrow translation.
- More testing will be needed to validate behavior.
@austindrenski

Copy link
Copy Markdown
Contributor Author

Closing for now per #489. The current behavior makes sense, pending comparison tests with SQL Server.

Also opening #496 to codify this behavior in the test suite and docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant