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 [摘要]:条件随机场用于序列标注,数据分割等自然语言处理中,表现出很好的效果.在中文分词.中文人名识别和歧义消解等任务中都有 ...
随机推荐
- 从0开始构建你的api网关--Spring Cloud Gateway网关实战及原理解析
API 网关 API 网关出现的原因是微服务架构的出现,不同的微服务一般会有不同的网络地址,而外部客户端可能需要调用多个服务的接口才能完成一个业务需求,如果让客户端直接与各个微服务通信,会有以下的问题 ...
- 第一册:lesson1-2.
原文: lesson 1 Excuse me! Excuse me! Yes? Is this your handbag? Pardon? Is this your handbag? Yes it i ...
- [转]webstorm中js文件被识别成txt类型
问题描述: webstorm中index.js文件被识别成txt格式,如下图. 原因: webstorm中js文件被识别成txt文件,原因在于txt类型识别了以当前js文件名命名的模式. 解决办法: ...
- 度分秒转换十进制度 之Excel实现
我们都知道,1°=60′,1′=60″,1°=3600″.那么,轻而易举容易计算:112°18′37.6″=112+18/60+37.6/3600≍112.3104444°这当然是有参考价值的,比如爬 ...
- Dynamics Business Central-如何配置VS Code连接BC环境
最近在研究Business Central,也就是以前的Dynamics NAV,需要配置Visual Studio Code连接BC环境,以下是配置的具体步骤. 1. VS Code下载,这个不多说 ...
- js生成[n,m]的随机数,js如何生成随机数,javascript随机数Math.random()
一.预备知识 Math.ceil(); //向上取整. Math.floor(); //向下取整. Math.round(); //四舍五入. Math.random(); //0.0 ~ 1 ...
- 【专题教程第8期】基于emWin模拟器的USB BULK上位机开发,仅需C即可,简单易实现
说明:1.如果你会emWin话的,就可以轻松制作上位机.做些通信和控制类上位机,比使用C#之类的方便程度一点不差,而且你仅会C语言就可以.2.并且成功将emWin人性化,可以做些Windows系统上的 ...
- Java实现发送手机验证码功能(短信+语音)
利用第三方平台可以实现发送手机短信验证码和语音验证码的功能,本文使用框架是struts2+spring+hibernate,现就action层给出核心代码功能. public class Verify ...
- Java进阶篇设计模式之二 ----- 工厂模式
前言 在上一篇中我们学习了单例模式,介绍了单例模式创建的几种方法以及最优的方法.本篇则介绍设计模式中的工厂模式,主要分为简单工厂模式.工厂方法和抽象工厂模式. 简单工厂模式 简单工厂模式是属于创建型模 ...
- Spring Boot 2.0 的快速入门(图文教程)
摘要: 原创出处 https://www.bysocket.com 「公众号:泥瓦匠BYSocket 」欢迎关注和转载,保留摘要,谢谢! Spring Boot 2.0 的快速入门(图文教程) 大家都 ...