❔ Exclude items from linq query if they contain one from an array of substrings
I've got a list of strings, that if they appear anywhere in a linq query column i want to exclude the row. I can find loads of examples of exact matches, or where the column value appears in a list, but not the other way around, and I can't figure it out
10 Replies
var providers = from st in context.Providers
where st.Practice == dbPractice.FirstOrDefault() && st.Active
&& !exclusions.Contains(st.Name)
select st;
this is the reverse, looking to see if st.Name appears in any of the strings in exclusions (List<string>) but i want it the other way around
What do you mean "the other way around"?
Whether a list of exclusions is contained in the name?
yea
exactly that
and then i'll drop those out
Uh, I can already say that
"Thomas"
will not contain [ "Bob", "Catherine", "Thomas" ]
no matter what you do
The list can contain the name
The name can't really contain a listquite
if the exlucsion list was ["a","e"]
then Thomas would be kicked out
but Bob wouldn't
basically - I probably can't do it in linq?
I tried a function whic returns bool, but linq to sql doens't like that of course
Something like this
ah okay, I did see an exmaple similar,
let me try that
As a side note, any reason to use Lin12Sql instead of Entity Framework Core?
sorry this is EFCore, apologies
not linq to sql
oh no
i'm confused
thank you tho
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.