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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -