MyDAL - in && not in 条件 使用
索引:
一.API 列表
C# 代码中 接口 IList.Contains() 方法生成 SQL 对应的 in(val1,val2,... ...)
如:.Queryer<Agent>()
... ...
.Where(it => new AgentLevel?[] { AgentLevel.CityAgent, AgentLevel.DistiAgent }.Contains(it.AgentLevel))
... ... 用于 单表 in 条件
.Queryer(out Agent agent, out AgentInventoryRecord record)
... ...
.Where(() => !new AgentLevel?[] { AgentLevel.CityAgent, AgentLevel.DistiAgent }.Contains(agent.AgentLevel))
... ... 用于 多表连接 in 条件
二.API 单表-便捷 方法 举例
1. in 条件
var res2 = await Conn
.QueryListAsync<Agent>(it => new List<AgentLevel?> { AgentLevel.CityAgent, AgentLevel.DistiAgent }.Contains(it.AgentLevel));
以 MySQL 为例,生成 SQL 如下:
select *
from `agent`
where `AgentLevel` in (?AgentLevel_2,?AgentLevel_3);
2. not in 条件
var res2 = await Conn
.QueryListAsync<Agent>(it => !new List<AgentLevel?> { AgentLevel.CityAgent, AgentLevel.DistiAgent }.Contains(it.AgentLevel));
以 MySQL 为例,生成 SQL 如下:
select *
from `agent`
where `AgentLevel` not in (?AgentLevel_2,?AgentLevel_3);
三.API 单表-完整 方法 举例
1. in 条件
var res5 = await Conn
.Queryer<Agent>()
.Where(it => new List<string> { "黄银凤", "刘建芬" }.Contains(it.Name))
.QueryListAsync();
以 MySQL 为例,生成 SQL 如下:
select *
from `agent`
where `Name` in (?Name_2,?Name_3);
2. not in 条件
var res5 = await Conn
.Queryer<Agent>()
.Where(it => !new List<string> { "黄银凤", "刘建芬" }.Contains(it.Name))
.QueryListAsync();
以 MySQL 为例,生成 SQL 如下:
select *
from `agent`
where `Name` not in (?Name_2,?Name_3);
四.API 多表连接-完整 方法 举例
1. in 条件
var res1 = await Conn
.Queryer(out Agent agent, out AgentInventoryRecord record)
.From(() => agent)
.InnerJoin(() => record)
.On(() => agent.Id == record.AgentId)
.Where(() => new AgentLevel?[] { AgentLevel.CityAgent, AgentLevel.DistiAgent }.Contains(agent.AgentLevel))
.QueryListAsync<Agent>();
以 MySQL 为例,生成 SQL 如下:
select agent.`*`
from `agent` as agent
inner join `agentinventoryrecord` as record
on agent.`Id`=record.`AgentId`
where agent.`AgentLevel` in (?AgentLevel_5,?AgentLevel_6);
2. not in 条件
var res1 = await Conn
.Queryer(out Agent agent, out AgentInventoryRecord record)
.From(() => agent)
.InnerJoin(() => record)
.On(() => agent.Id == record.AgentId)
.Where(() => !new AgentLevel?[] { AgentLevel.CityAgent, AgentLevel.DistiAgent }.Contains(agent.AgentLevel))
.QueryListAsync<Agent>();
以 MySQL 为例,生成 SQL 如下:
select agent.`*`
from `agent` as agent
inner join `agentinventoryrecord` as record
on agent.`Id`=record.`AgentId`
where agent.`AgentLevel` not in (?AgentLevel_5,?AgentLevel_6);
五.数组 Array 举例
1. in 条件
var enumArray = new AgentLevel?[]
{
AgentLevel.CityAgent,
AgentLevel.DistiAgent
}; var res12 = await Conn
.Queryer<Agent>()
.Where(it => enumArray.Contains(it.AgentLevel))
.QueryListAsync();
以 MySQL 为例,生成 SQL 如下:
select *
from `agent`
where `AgentLevel` in (?AgentLevel_2,?AgentLevel_3);
2. not in 条件
var res1 = await Conn
.Queryer<Agent>()
.Where(it => !new AgentLevel?[] { AgentLevel.CityAgent, AgentLevel.DistiAgent }.Contains(it.AgentLevel))
.QueryListAsync();
以 MySQL 为例,生成 SQL 如下:
select *
from `agent`
where `AgentLevel` not in (?AgentLevel_2,?AgentLevel_3);
六.列表 List<T> 举例
1. in 条件
var enums = new List<AgentLevel?>
{
AgentLevel.CityAgent,
AgentLevel.DistiAgent
}; var res1 = await Conn
.Queryer<Agent>()
.Where(it => enums.Contains(it.AgentLevel))
.QueryListAsync();
以 MySQL 为例,生成 SQL 如下:
select *
from `agent`
where `AgentLevel` in (?AgentLevel_2,?AgentLevel_3);
2. not in 条件
var res1 = await Conn
.Queryer<Agent>()
.Where(it => !new List<AgentLevel?> { AgentLevel.CityAgent, AgentLevel.DistiAgent }.Contains(it.AgentLevel))
.QueryListAsync();
以 MySQL 为例,生成 SQL 如下:
select *
from `agent`
where `AgentLevel` not in (?AgentLevel_2,?AgentLevel_3);
蒙
2019-03-04 22:10 周一
2019-04-13 20:28 周六
MyDAL - in && not in 条件 使用的更多相关文章
- MyDAL - like && not like 条件 使用
索引: 目录索引 一.API 列表 C# 代码中 String.Contains("conditionStr") 生成 SQL 对应的 like '%conditionStr%' ...
- MyDAL - .Where() 之 .WhereSegment 根据条件 动态设置 Select查询条件 使用
索引: 目录索引 一.API 列表 1.WhereSegment 属性,指示 根据条件 动态拼接 where 查询过滤条件 见如下示例. 二.API 单表-完整 方法 举例 // 上下文条件 变量 v ...
- MyDAL - .UpdateAsync() 之 .SetSegment 根据条件 动态设置 要更新的字段 使用
索引: 目录索引 一.API 列表 1.SetSegment 属性,指示 根据条件 动态拼接 要修改的字段 见如下示例. 二.API 单表-完整 方法 举例 // update 要赋值的变量 var ...
- MyDAL - is null && is not null 条件 使用
索引: 目录索引 一.API 列表 C# 代码中 instance.property == null 生成 SQL 对应的 is null : 如:.Queryer<Agent>() .. ...
- MyDAL - 快速使用
索引: 目录索引 一.安装 在 VS 中执行一下 package 命令: PM> Install-Package MyDAL 二.API-快速使用 1.命名空间,只需: using MyDAL; ...
- Python学习--04条件控制与循环结构
Python学习--04条件控制与循环结构 条件控制 在Python程序中,用if语句实现条件控制. 语法格式: if <条件判断1>: <执行1> elif <条件判断 ...
- ASP.NET Core应用针对静态文件请求的处理[2]: 条件请求与区间请求
通过调用ApplicationBuilder的扩展方法UseStaticFiles注册的StaticFileMiddleware中间件帮助我们处理针对文件的请求.对于StaticFileMiddlew ...
- 多线程条件通行工具——AbstractQueuedSynchronizer
本文原创,转载请注明出处! 参考文章: <"JUC锁"03之 公平锁(一)> <"JUC锁"03之 公平锁(二)> AbstractOw ...
- 【NLP】前戏:一起走进条件随机场(一)
前戏:一起走进条件随机场 作者:白宁超 2016年8月2日13:59:46 [摘要]:条件随机场用于序列标注,数据分割等自然语言处理中,表现出很好的效果.在中文分词.中文人名识别和歧义消解等任务中都有 ...
随机推荐
- 微信公众号开发C#系列-11、生成带参数二维码应用场景
1.概述 我们在微信公众号开发C#系列-7.消息管理-接收事件推送章节有对扫描带参数二维码事件的处理做了讲解.本篇主要讲解通过微信公众号开发平台提供的接口生成带参数的二维码及应用场景. 微信公众号平台 ...
- How to build ffmpeg with hardware accelerated codecs for Android x86
In order to build a complete ffmpeg with hardware acceleration for Intel platform (XXX lake + Atom), ...
- Android利用RecyclerView实现列表倒计时效果
最近面试时,面试官问了一个列表倒计时效果如何实现,然后脑袋突然懵的了O(∩_∩)O,现在记录一下. 运行效果图 实现思路 实现方法主要有两个: 1.为每个开始倒计时的item启动一个定时器,再做更新i ...
- SqlServer中用SQL语句附加数据库及修改数据库逻辑文件名
--查询数据库逻辑文件名 USE 数据库名 SELECT FILE_NAME(1) --查询数据库逻辑文件名(日志) USE 数据库名 SELECT FILE_NAME(2) --附加数据库 sp_a ...
- .NET Core 时代已经到了,你准备好了吗
今天很多人都收到了阿里云函数计算支持.NET Core的短信了. 通过访问 https://help.aliyun.com/document_detail/112379.html 你可以看到最新的说明 ...
- Kafka的partions和replication-factor参数的理解
Topic在Kafka中是主题的意思,生产者将消息发送到主题,消费者再订阅相关的主题,并从主题上拉取消息. 在创建Topic的时候,有两个参数是需要填写的,那就是partions和replicatio ...
- C#实现将Chart图表生成JPG图片的方法
SaveFileDialog savefile= new SaveFileDialog(); savefile.Filter = "JPEG文件|*.jpg" ...
- lua-nginx-module模块里ngx_lua的所有指令以及可用ngx所有方法
http://www.04007.cn/article/430.html
- [intellij IDEA]导入eclipse项目
1.因为最近eclipse在更新代码时经常卡死,就想将eclipse的项目迁移到idea.特意写下自己的经验,给迁移时遇到困难的朋友一些帮助 File -> new ->project f ...
- golang中Context的使用场景
golang中Context的使用场景 context在Go1.7之后就进入标准库中了.它主要的用处如果用一句话来说,是在于控制goroutine的生命周期.当一个计算任务被goroutine承接了之 ...