随笔 - 432  文章 - 0  评论 - 15  阅读 - 63万

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
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连接查询连接不同的集合,不会自动过滤相同项;延迟。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(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相交查询:获取不同集合的相同项(交集),即两集合都出现的项。

1
2
3
4
5
6
7
(from c in Bst_System_Places
 
select c.CnPlaceName).Intersect(
 
from e in Bst_Company_Jobs
 
select e.WorkPlace)

  

 

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

1
2
3
4
5
6
7
(from e in Bst_Company_Jobs
 
select e.WorkPlace).Except(
 
from c in Bst_System_Places
 
select c.CnPlaceName)

  

 

posted on   狼来了  阅读(830)  评论(0编辑  收藏  举报
编辑推荐:
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· NetPad:一个.NET开源、跨平台的C#编辑器
历史上的今天:
2014-07-26 完全解读 margin 标签
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

点击右上角即可分享
微信分享提示