索引:

目录索引

一.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. cshtml中正则表达式使用后台代码

    //定义变量 bool a = false; //正则表达式 string b = @" ^ (13[0 - 9] | 14[5 | 7] | 15[0 | 1 | 2 | 3 | 5 | ...

  2. JavaScript 新语法详解:Class 的私有属性与私有方法

    译者按: 为什么偏要用 # 符号? 原文:JavaScript's new #private class fields 译者:Fundebug 本文采用意译,版权归原作者所有 proposal-cla ...

  3. 4.熟悉App Inventor 2编程界面

    以下图片来自 https://www.17coding.net/的 俄罗斯方块开发笔记 的 第二章 开发与测试环境 .感谢金老师的分享. 建议大家打开上面第二章的链接,认真阅读.

  4. gitbook 入门教程之环境要求

    gitbook 是基于 node.js 的命令行工具,首先需要安装并配置好 node.js 环境,然后才能安装gitbook 相关工具. 由于安装工具全部都是国外网站,因此速度可能会很慢,也可能需要F ...

  5. Ubuntu安装apache+Yii2

    1.下载Yii2 https://www.yiichina.com/download 2.将解压后的文件放在指定的位置,这里是/home/www/yii/ 3.安装apache2 sudo apt-g ...

  6. “.Net 社区大会”(dotnetConf) 2018 Day 1 主题演讲

    Miguel de Icaza.Scott Hunter.Mads Torgersen三位大咖给大家带来了 .NET Core ,C# 以及 Xamarin的精彩内容: 6月份已经发布了.NET Co ...

  7. SCSS & SASS Color 颜色函数用法

    最近做一个没有设计师参与的项目,发现 scss 内置的颜色函数还挺好用.记录分享下 rgba() 能省掉手工转换 hex 到 rgb 格式的工作,如以下 SCSS 代码 $linkColor: #20 ...

  8. ajax data属性传值的方式总结

    在和后台同事对接口的时候,有一个小问题一直困扰着我.那就是用ajax请求后台接口数据,需要用data属性传值的时候,data属性传值的方式感觉没有统一用一种方式. 后来仔细想想,其实哪种方式都可以,主 ...

  9. [Swift-2019力扣杯春季决赛]3. 最长重复子串

    给定字符串 S,找出最长重复子串的长度.如果不存在重复子串就返回 0. 示例 1: 输入:"abcd" 输出:0 解释:没有重复子串. 示例 2: 输入:"abbaba& ...

  10. 从壹开始前后端分离 [ Vue2.0+.NET Core2.1] 二十五║初探SSR服务端渲染(个人博客二)

    缘起 时间真快,现在已经是这个系列教程的下半部 Vue 第 12 篇了,昨天我也简单思考了下,可能明天再来一篇,Vue 就基本告一段落了,因为什么呢,这里给大家说个题外话,当时写博文的时候,只是想给大 ...