Entity Framework not comparing byte arrays

c# entity-framework entity-framework-6 hash

Question

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?

1
3
11/22/2019 5:39:43 AM

Accepted Answer

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

var foundRequest = _complianceContext.ScoreResults
  .Where(sr => sr.SequenceEqual(searchHash));
6
1/25/2017 9:25:20 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow