If I have the following query where Companies.Name
is encrypted:
Obviously executing the following query is going to be invalid because we're searching against encrypted names.
IQueryable<File> files = GetFiles(f => f.Clients.Any(fc => fc.Contacts.Any(c => c.Companies.Any(x => x.Name.Contains(searchText)))));
I'm after a way to decrypt Companies.Name
before the query is executed via a Decrypt()
function we already have in place.
EDIT 1:
I do have a partial class Company
with a decrypted property called DisplayName
that returns the decrypted Name
property, however LINQ is telling me the specified type member DisplayName
is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
IQueryable<File> files = GetFiles(f => f.Clients.Any(fc => fc.Contacts.Any(c => c.Companies.Any(x => x.DisplayName.Contains(searchText)))));
If there's a way to use a partial class property inside a LINQ statement I guess it would work.
EDIT 2:
I ended up creating a SQL CLR function that decrypts the company names and I can now call dataContext.SearchCompanies(searchText)
in code to return a list of Companies
.
I'm not sure however, how to easily replace Companies
within the original list?