I’ve a table that includes a binary field (says “bin”) which contains 14 bytes data. I want to do a search on this field as below:
from row in db.users where row.bin.SequenceEqual(data) select row
the type of “data” variable is byte[].
but when I run “q.Count()”, I encounter the following error:
LINQ to Entities does not recognize the method 'Boolean SequenceEqual[Byte] (System.Collections.Generic.IEnumerable`1[System.Byte], System.Collections.Generic.IEnumerable`1[System.Byte])' method, and this method cannot be translated into a store expression.
How can I retrieve the count of matches binary data?
Thanks
If you own the data model, and your binary data is small fixed-size array of bytes, you can change the SQL data type from
binary(14)tochar(21), useConvert.ToBase64Stringon the way into the database, andConvert.FromBase64Stringon the way out.Switching to string will make your data searchable: simply encode your search
dataas base64 string, and use the==operator in the search condition.