LinQ中合并、连接、相交、与非查询

LinQUnion合并查询连接不同的集合,自动过滤相同项;延迟。即是将两个集合进行合并操作,过滤相同的项

 

var cities = (from p in mylinq.System_Places



          where p.PID == place



          select p).Union(



          from q in mylinq.System_Places



          where q.Parentid==place



          select q



          );

LinQ中的Concat连接查询连接不同的集合,不会自动过滤相同项;延迟。

(from p in System_Places



     where p.PID == 1010



     select p).Concat(



       from q in System_Places



         where q.Parentid==1010



         select q



         ).Concat(



           from n in System_Places



             where n.Parentid==1010



              select n

   )

 

 

LinQ中的Intersect相交查询:获取不同集合的相同项(交集),即两集合都出现的项。

(from c in Bst_System_Places



  select c.CnPlaceName).Intersect(



  from e in Bst_Company_Jobs



  select e.WorkPlace)


LinQ中的Except与非查询:排除相交项,即从某集合中排除与另一集合中相同的项,以前集合为主。。。

(from e in Bst_Company_Jobs



  select e.WorkPlace).Except(



  from c in Bst_System_Places



  select c.CnPlaceName)


转自:http://mwga.net.blog.163.com/blog/static/106456728201063044736712/

你可能感兴趣的:(LINQ)