说明:用于判断集合中是否包含有某一元素;不延迟。它是对两个序列进行连接操作的。
string[] customerID_Set =
new string[] { "AROUT", "BOLID", "FISSA" };
var q = (
from o in db.Orders
where customerID_Set.Contains(o.CustomerID)
select o).ToList();
语句描述:查找"AROUT", "BOLID" 和 "FISSA" 这三个客户的订单。先定义了一个数组,在LINQ to SQL中使用Contains,数组中包含了所有的CustomerID,即返回结果中,所有的CustomerID都在这个集合内。也就是in。 你也可以把数组的定义放在LINQ to SQL语句里。比如:
var q = ( from o in db.Orders where ( new string[] { "AROUT", "BOLID", "FISSA" }) .Contains(o.CustomerID) select o).ToList();
总结:
var tagMapIdList = from tagMap in nplusDatabaseDataContext.TagMap
where contentId == tagMap.ContentId
select tagMap.TagId;
var tagIdList = from tag in nplusDatabaseDataContext.Tag
where tagMapIdList.Contains(tag.Id) && tag.ContentType == contentType
select tag.Id;
如果查找数据中是否存在单个值时,可直接取值。
如果需查找多个数据时。
1、 数据需存在string[]里进行查找
2、 Linq to Sql 语句查出的多个值,不能First()及ToList(),只有是Linq语句时,才可以查找