What you need is !slist.Contains(s.ShipName)
like:
(from s in ctx.Shipments
where !slist.Contains(s.ShipName)
).ToList();
You may see this article for creating IN query with LINQ
Pregunta
I have a List<string>
that contains a number of string values.
Can I filter a collection when doing a query with a list instead of a single value?
Something like this:
List<string> slist = new List<string>() { "val 1", "val 2", "val 3" };
var q = (from s in ctx.Shipments
where !s.ShipName.ToList().Contains(slist)).ToList()
Solución
What you need is !slist.Contains(s.ShipName)
like:
(from s in ctx.Shipments
where !slist.Contains(s.ShipName)
).ToList();
You may see this article for creating IN query with LINQ
Otros consejos
from sn in ctx.ShipNames
where !slist.Contains(sn.Name)
select sn.Shipment
May be you can go from the ShipName entity
Try this one:
List<string> slist = new List<string>() {"val 1", "val 2", "val 3"};
(from s in ctx.Shipments where !slist.Contains(s.ShipName).ToList();
This way you will get all the records of the Shipments, whose name isn't included in the slist
.