-
Notifications
You must be signed in to change notification settings - Fork 228
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
Exception when doing a Contains query against an enum field based on byte #1189
Comments
There's some difficulty around byte arrays, since they can map to both PostgreSQL Note: this can be reproduced without enums: var bytes = new byte[] { 1, 2, 3 };
var result = await dbContext.My.Where(e => bytes.Contains(e.RealByte)).ToListAsync(); |
@roji If we were willing to try to create a PR for this, any suggestions where we should start looking? |
This would basically be an implementation of dotnet/efcore#4601 (already done for SQL Server and Sqlite) for the Npgsql provider. We'd translate Contains over byte arrays in a specific way (by using PostgreSQL position) before the general array logic kicks in. Following what was done for the other providers, we'd add an NpgsqlByteArrayMethodTranslator where that translation would take place. Good luck and let me know if you need any more guidance! If you end up not having time, please post a note here so I know to take care of it myself. |
A quick workaround is to provide an IList of T i.s.o. a T[] in the where clause: IList<Status> list = new []{ Status.Enabled, Status.Disabled };
dbContext.My.Where(e => list.Contains(e.SomeByteValue)) |
Good idea! |
@roji As we have an easy workaround for now I think we won't pick this one up, I suspect you'll be able to get this done way faster than we will anyway :) I appreciate the pointers though, if our workload was a bit lighter we could spend some time investigating getting a real fix done. |
Sure thing, no problem! |
Changing milestone to 5.0.0 as the fix isn't trivial and there's a good workaround. |
I have the same issue... Is it fixed only in .Net 5? Workaround with "short" does not work. |
@freerider7777 this issue is fixed only in EF Core 5.0 (as indicated by the milestone). If you're seeing other exceptions when using EF Core 5.0 (e.g. with |
We just upgraded to EFCore 3.1 which surfaced this issue.
Minimal reproduction:
Repro.csproj:
Program.cs
This line:
throws the following exception:
Stacktrace:
The text was updated successfully, but these errors were encountered: