-
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
Translate SequenceEquals for byte arrays #10582
Comments
re this
Is there some way to be notified when, some usage of code in c#, translates to the entire table being loaded into memory? Eg an event, or a config flag to log it as an error? |
In case anyone else runs into this difference between in-memory and translated SQL, there is a possible workaround as listed here: Which involves mapping the |
How can that possibly work for arrays longer than 8 bytes though? Mine are up to 512. |
Good point. I found this issue with my With that said, you might be able to do a similar value conversion to something that can be compared with |
I have a solution, but it means my unit tests (which use an InMemory database) aren't using the same query as my production code. But I guess that's what integration tests are for. |
A related issue is this technique in EF6 to compare byte arrays: |
Having to add (InMemory && SequenceEqual(bytes, bytes2)) || (bytes == bytes2) to all my queries, royal pain in the butt. Why is SequenceEqual not simply treated as straight up equals for sql generation? |
Thanks so much for fixing this, I really appreciate it! |
+1 thanks for the fix. Any idea which version of EF this might crop up in? |
@JoshSchreuder it is in the v5 milestone. which i believe is a november eta |
Always feel free to use the daily builds to provide early feedback on cool new features like this. Note, there are some bad packages on the feed at the moment that might prevent you from getting the latest; use the following version to work around it. <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer"
Version="5.0.0-alpha.*" /> |
@bricelam FYI After reading your comment I added this workaround to the daily builds information in the weekly status:
|
A
where
clause using == onbyte[]
translates into the SQL to compare the underlying value data, despite the fact that the C# syntax for doing this requiresSequenceEquals()
or similar.Specifically
myTable.Where(r => r.ByteArray == byteArray)
is the only way to produce the SQL, "WHERE ByteArray = @bytearray", which works as expected and ensures the data comparison is performed by SQL server, but fails to work using e.g. the InMemory EF provider, or if your data source is any in-memory data structure.OTOH,
myTable.Where(r => r.ByteArray.SequenceEquals(byteArray))
works with in-memory data stores, but doesn't translate into SQL, causing the entire table to be loaded into memory.Given the behaviour of == for
byte[]
can't be changed at the .NET level, I would expect.SequenceEquals( )
to be translated to SQL = for byte arrays.Further technical details
EF Core version: 2.0.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2017 15.4
The text was updated successfully, but these errors were encountered: