I have a LINQ result set I'm trying to filter in a strange and peculiar way.
List<string> MyDomains = [Code to get list];
var x = (from a in dc.Activities
where a.Referrer != null
&& a.Referrer.Trim().Length > 0
&& !a.Referrer.Contains("localhost")
&& a.SearchResults.Count() == 0
orderby a.ID descending
select a)
.Take(20);
Now that I have that out of the way, let me explain it better. MyDomains is a list of strings; each one is a root domain I own.
a.Referrer is a string containing a referrer from a GET to one of my websites. Note this string will contain subdomains, folders, files, and querystrings.
I want to filter x by the root domain of a.Referrer being in the MyDomains list. That is, I want to return all records that do not match in this way. The result set should end up containing Activities whose Referrer is not one of my domains.
I've been learning Lambda expressions, but so far haven't been able to craft one to meet this goal since it effectively needs a where clause with logic inside it (Possibly loops, substrings, etc).
Currently I'm thinking of casting X to a List, filtering them manually, then binding the list to the target control instead of binding X. I have an extension method to get the root domain of a Uri and another to determine whether it's my domain, but can't put them in a Lambda here because they have "no supported translation to SQL".
Architectural disagreements aside, how can I fulfill this from within my LINQ query?
Edit: Note I want to do this from within the query so I remove the matched records before my .Take(20) is added. I'd like to get the same number of results every time without having to call the database for more.