Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework not comparing byte arrays

I am inserting data, using EF, which contains a SHA512 Hash. I am then looking up the same data like this, but no results are returned:

var searchHash = requestToFind.GetSelfSha512Hash();
var foundRequest = _complianceContext.ScoreResults
    .Where(sr => sr.SearchHash == searchHash);

Both sr.SearchHash and searchHash are byte[].

If I take out the Where clause, I do get 1 result. Any ideas why this may be?

like image 554
FailedUnitTest Avatar asked Mar 10 '23 01:03

FailedUnitTest


1 Answers

The equality operator does not work like you expect for byte arrays. Try SequenceEqual.

var foundRequest = _complianceContext.ScoreResults
  .Where(sr => sr.SequenceEqual(searchHash));
like image 188
chadnt Avatar answered Mar 15 '23 00:03

chadnt