索引:

目录索引

一.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. Elasticsearch最佳实践之分片使用优化

    本文由云+社区发表 作者:老生姜 一.遇到的问题 与大多数分布式系统一样,Elasticsearch按照一定的Hash规则把用户数据切分成多个分片,然后打散到不同机器进行存储,从而实现大规模数据的分布 ...

  2. cshtml中正则表达式使用后台代码

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

  3. 02. Install redis on Linux

    安装下载redis,参考官方文档:https://redis.io/download 下载: shell>wget http://download.redis.io/releases/redis ...

  4. C++11新特性之tie、tuple的应用

    //tuplestd::tuple<int, int, int, int, QString> Thorface::getUserInfoToJudgeOpendoor(QString st ...

  5. kerberos环境storm配置:Running Apache Storm Securely

    Running Apache Storm Securely Apache Storm offers a range of configuration options when trying to se ...

  6. erlang 删除老版本 安装新版本

    [root@izbp1buyhgwtrvlxv3u2gqz ~]# yum remove erlang-erts-R16B-03.18.el7.x86_64Loaded plugins: fastes ...

  7. 详解docker实战之搭建私有镜像仓库 - kurbernetes

    1.实战目的 搭建企业私有的镜像仓库,满足从开发环境推送和拉取镜像.当我们使用k8s来编排和调度容器时,操作的基本单位是镜像,所以需要从仓库去拉取镜像到当前的工作节点.本来使用公共的docker hu ...

  8. C# 《编写高质量代码改善建议》整理&笔记 --(五)成员设计

    1.可以字段应该重构为属性 2.谨慎将数组或集合作为属性 数组和集合作为属性存在会引起这样的一个分歧:如果属性是只读的,我们通常会认为他是不可改变的.但是如果将只读属性应用于数组和集合,而元素的内容和 ...

  9. ColorUtil【Color工具类(color整型、rgb数组、16进制互相转换)】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 主要用于color整型.rgb数组.16进制互相转换(-12590395 <--> #3FE2C5 <--> ...

  10. unity中ScriptableObject在assetbundle中的加载

    转载请标明出处:http://www.cnblogs.com/zblade/ 以前都是写一些个人的调研博客,从今天开始,也写一些个人在开发中遇到的一些可以分享的趟坑博客,为后续的开发人员提供一些绵薄之 ...