문제

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()
도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top