I need to compare binary values in a query done by Linq2sql.
table1.FirstOrDefault(r => r.ID.SequenceEqual(id))//ID and id are binary/byte[].
but Linq2sql is throwing an exception because SequenceEqual
cannot be executed in it because it's not defined for SQL.
I found this answer which creates a new Compare
method to confuse Linq into allowing it.
But then I found that ==
works as well since SQL compares binaries byte-by-byte anyway.
But since I saw that answer which didn't bring this simple solution, I was wondering if it will really work all the time.
So, is there any pitfall I'm missing here?
As @Sonal said
==
will always work for comparingbyte[]
or any other data type that supports equality comparison, However the question you mention does not check equality, but it asks for greather than and less than operators (>
and<
) for a data type that does not support them, so a custom comparison method is needed.