I have a database containing a table with an “Image” colum:

This column actually contains a long string encoded as HEX byte values.
I need to select all records where the string encoded by this column contains a certain substring. Pseudocode would be:
Select *
From SomeTable
Where dataColumnofTypeImage.ToString().Contains("somesubstring")
I tried to do this in Linq (LinqPad) using:
from z in Zanus
let p = z.Udata.ToArray() // z.Udata will be of type System.Linq.Binary so I want to make a byte array out of it...
where System.Text.ASCIIEncoding.ASCII.GetString(p).Contains("EXED")
select new
{
z.Idnr,
z.Udatum,
z.Uzeit,
z.Unr,
z.Uart,
z.Ubediener,
z.Uzugriff,
z.Ugr,
z.Uflags,
z.Usize,
z.Udata
}
But this does not work at all saying:
NotSupportedException: Method ‘Byte[] ToArray()’ has no supported translation to SQL.
I just cannot believe it would not be possible to check a binary datatype in a Where clause just as I might check some other datatype…
Can somebody help me out here?
The only way I know of doing this is to use direct sql and the Substring
For example, something like :
Note, this will fail if the search string is in a column, but not in the first 2,147,483,647 bytes (but if these are images, I don’t think that should be a concern).