c# - LINQ where db table does not contain in memory list elements -
i have seen these stackoverflow answers not produce same results when filtering list in memory.
i have list of ids. want remove ids exists in database, left list of ids need added. in other words, need perform where not in
sql query, using linq-to-entities. problem is, instead of producing sql, these methods each produce sql query per list item.
var providerids = new [] {"1130", "1", "16"};
method 1:
var missingproviders = (from provider in providerids !jobproviders.any(p => p.jobproviderid == provider) select provider).tolist();
method 2:
var missingproviders = (from provider in providerids !(from p in jobproviders select p.jobproviderid).contains(provider) select provider).tolist();
is there way structure linq query such produces intended not in
form, or these solutions?
what like
var providersindb = (from provider in jobproviders providerids.contains(provider.jobproviderid) select provider.jobproviderid).tolist(); var missingproviders = providerids.where(p => !providersindb.contains(p))
Comments
Post a Comment