天天看點

Linq to SQL Contains

說明:用于判斷集合中是否包含有某一進制素;不延遲。它是對兩個序列進行連接配接操作的。

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語句時,才可以查找