索引:

目录索引

一.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 条件 使用的更多相关文章

  1. MyDAL - like && not like 条件 使用

    索引: 目录索引 一.API 列表 C# 代码中 String.Contains("conditionStr") 生成 SQL 对应的 like '%conditionStr%' ...

  2. MyDAL - .Where() 之 .WhereSegment 根据条件 动态设置 Select查询条件 使用

    索引: 目录索引 一.API 列表 1.WhereSegment 属性,指示 根据条件 动态拼接 where 查询过滤条件 见如下示例. 二.API 单表-完整 方法 举例 // 上下文条件 变量 v ...

  3. MyDAL - .UpdateAsync() 之 .SetSegment 根据条件 动态设置 要更新的字段 使用

    索引: 目录索引 一.API 列表 1.SetSegment 属性,指示 根据条件 动态拼接 要修改的字段 见如下示例. 二.API 单表-完整 方法 举例 // update 要赋值的变量 var ...

  4. MyDAL - is null && is not null 条件 使用

    索引: 目录索引 一.API 列表 C# 代码中 instance.property == null 生成 SQL 对应的 is null : 如:.Queryer<Agent>() .. ...

  5. MyDAL - 快速使用

    索引: 目录索引 一.安装 在 VS 中执行一下 package 命令: PM> Install-Package MyDAL 二.API-快速使用 1.命名空间,只需: using MyDAL; ...

  6. Python学习--04条件控制与循环结构

    Python学习--04条件控制与循环结构 条件控制 在Python程序中,用if语句实现条件控制. 语法格式: if <条件判断1>: <执行1> elif <条件判断 ...

  7. ASP.NET Core应用针对静态文件请求的处理[2]: 条件请求与区间请求

    通过调用ApplicationBuilder的扩展方法UseStaticFiles注册的StaticFileMiddleware中间件帮助我们处理针对文件的请求.对于StaticFileMiddlew ...

  8. 多线程条件通行工具——AbstractQueuedSynchronizer

    本文原创,转载请注明出处! 参考文章: <"JUC锁"03之 公平锁(一)> <"JUC锁"03之 公平锁(二)> AbstractOw ...

  9. 【NLP】前戏:一起走进条件随机场(一)

    前戏:一起走进条件随机场 作者:白宁超 2016年8月2日13:59:46 [摘要]:条件随机场用于序列标注,数据分割等自然语言处理中,表现出很好的效果.在中文分词.中文人名识别和歧义消解等任务中都有 ...

随机推荐

  1. Dapper 链式查询 扩展

    Dapper 链式查询扩展 DapperSqlMaker   Github地址:https://github.com/mumumutou/DapperSqlMaker  欢迎大佬加入 Demo: 查询 ...

  2. 将一个html文件引入另一个html文件的div中

    width="" height=""属性可根据要求自己设定

  3. 基于BootstarbTable实现加载更多的方式

    在工作中,我们有时候会遇到一些需求实现每次在页面上显示的数据每次都是通过请求数据库端来实现,在不通过上一页,下一页的方式来实现我们要展示的数据,通过js请求每次加载10条或者任意数量的数据. 代码展示 ...

  4. 第三周LINUX学习笔记

    周期性任务丶find 文件查找:find命令 locate :在数据库中查找,非实时查找,精确度不高,查找速度快,模糊查找  /tmp/passwad/a.textfind:实时查找:速度慢  ,精确 ...

  5. Centos7.3离线(rpm方式)安装mysql服务

    1.mysql官网下载安装包,官网地址:www.mysql.com [root@seiang software]# ll total 580020 -rw-r--r--. 1 root root 59 ...

  6. JavaScript正则表达式基础

    ECMAScript 3 开始支持正则表达式,其语法和 Perl 语法很类似,一个完整的正则表达式结构如下: var expression = / pattern / flags ; 其中,模式(pa ...

  7. ASP.NET Aries 高级开发教程:使用存储过程(番外篇)

    前言: 发现这个问题,有不少人提起过,所以就简单写成文章吧. 接下来看如何在Aries 框架中使用存储过程,整体步骤和绑定普通视图差不多. 步骤一:新建一个空视图. 可以在SqlCode管理中,创建一 ...

  8. 从壹开始前后端分离【 .NET Core2.0 +Vue2.0 】框架之四 || Swagger的使用 3.2

    前言 如果想直接在域名的根目录直接加载 swagger 比如访问:localhost:8001 就能访问,可以这样设置: app.UseSwaggerUI(c => { c.SwaggerEnd ...

  9. .NET Core TDD 前传: 编写易于测试的代码 -- 单一职责

    第1篇: 讲述了如何创造"缝".  "缝"(seam)是需要知道的概念. 第2篇, 避免在构建对象时写出不易测试的代码. 第3篇, 依赖项和迪米特法则. 第4篇 ...

  10. js实现二分查找算法

    二分查找:是一种搜索某个值的索引的算法. 基本条件:有序的数组. 思路:1.将数组折半,分成左右两个数组. 2.判断要查找的数和中间位置数值的大小,来判断要查找的数实在哪一半. 3.之后继续折半查找, ...