適用場景:對兩個集合的處理,例如追加、合併、取相同項、相交項等等。spa
說明:鏈接不一樣的集合,不會自動過濾相同項;延遲。code
var q = ( from c in db.Customers select c.Phone ).Concat( from c in db.Customers select c.Fax ).Concat( from e in db.Employees select e.HomePhone );
語句描述:返回全部消費者和僱員的電話和傳真。blog
var q = ( from c in db.Customers select new { Name = c.CompanyName, c.Phone } ).Concat( from e in db.Employees select new { Name = e.FirstName + " " + e.LastName, Phone = e.HomePhone } );
語句描述:返回全部消費者和僱員的姓名和電話。io
說明:鏈接不一樣的集合,自動過濾相同項;延遲。便是將兩個集合進行合併操做,過濾相同的項。ast
var q = ( from c in db.Customers select c.Country ).Union( from e in db.Employees select e.Country );
語句描述:查詢顧客和職員所在的國家。class
說明:取相交項;延遲。便是獲取不一樣集合的相同項(交集)。即先遍歷第一個集合,找出全部惟一的元素,而後遍歷第二個集合,並將每一個元素與前面找出的元素做對比,返回全部在兩個集合內都出現的元素。select
var q = ( from c in db.Customers select c.Country ).Intersect( from e in db.Employees select e.Country );
語句描述:查詢顧客和職員同在的國家。遍歷
說明:排除相交項;延遲。便是從某集合中刪除與另外一個集合中相同的項。先遍歷第一個集合,找出全部惟一的元素,而後再遍歷第二個集合,返回第二個集合中全部未出如今前面所得元素集合中的元素。nio
var q = ( from c in db.Customers select c.Country ).Except( from e in db.Employees select e.Country );
語句描述:查詢顧客和職員不一樣的國家。查詢