I need to create a Linq query that would have the following logic:
IEnumerable<string> prefixes = GetListOfPrefixesFromSomewhere();
IQueryable<Record> myQuery = GetAllRecordsFromRepository();
foreach (string prefix in prefixes)
{
myQuery = myQuery.Where(x => !x.Field.StartsWith(prefix));
}
This would obviously result in a large IQueryable which can then be executed.
Is there a nice elegant way to express this is a single Linq statement?
You can at least try this:
Quite what the SQL will look like, I don’t know – but I think it’s logically what you want, which is usually a good start.