I have byte[] stored in a SQL Server database as varbinary(64) and I need to find a specific row with input byte[]. I'm using Entity Framework to access the database, thus I can run a linq query like this:
private MyTable GetMyTable(byte[] inputArray)
{
return _context.MyTable.FirstOrDefault(x => x.Hash.SequenceEqual(inputArray));
}
The issue is that SequenceEqual can't be translated into SQL query and the query will be evaluated locally (which is is undesirable behavior). Is it possible to replace SequenceEqual for simple compare operator ==? Or is this approach error-prone? Is there any better alternatives than this?
private MyTable GetMyTable(byte[] inputArray)
{
return _context.MyTable.FirstOrDefault(x => x.Hash == inputArray);
}
Note that my byte arrays will range from 32 to 64 bytes so it's not going to be huge array comparisons.