索引:

目录索引

一.API 列表

  C# 代码中 String.Contains("conditionStr") 生成 SQL 对应的 like '%conditionStr%'

    如:.Queryer<Agent>()

      ... ...

      .Where(it => it.PathId.Contains("~00-d-3-1-"))

      ... ... 用于 单表 like 条件

      .Queryer(out Agent agent1, out AgentInventoryRecord record1)

      ... ...

      .Where(() => agent1.Name.Contains("陈"))

      ... ... 用于 多表连接 like 条件

  C# 代码中 String.StartsWith("conditionStr") 生成 SQL 对应的 like 'conditionStr%'

    如:.Queryer<Agent>()

      ... ...

      .Where(it => it.PathId.StartsWith("~00-d-3-1-"))

      ... ... 用于 单表 like 条件

      .Queryer(out Agent agent13, out AgentInventoryRecord record13)

      ... ...

      .Where(() => agent13.Name.StartsWith("张"))

      ... ... 用于 多表连接 like 条件

  C# 代码中 String.EndsWith("conditionStr") 生成 SQL 对应的 like '%conditionStr'

    如:.Queryer<Agent>()

      ... ...

      .Where(it => it.PathId.EndsWith("~00-d-3-1-"))

      ... ... 用于 单表 like 条件

      .Queryer(out Agent agent13, out AgentInventoryRecord record13)

      ... ...

      .Where(() => agent13.Name.EndsWith("华"))

      ... ... 用于 多表连接 like 条件

  MySQL 通配符 %(百分号)  /  _(下划线)

     在 string 变量中若检测到 通配符 存在,则以自定义的通配符表达式 在 DB 中进行 like 查询

  C# 代码中 通配符转义 /%(百分号转义)  /  /_(下划线转义)

        在 string 变量中若检测到 通配符转义 存在 ,则会在 DB 中以转义后 字面值 的形式进行 like 查询

二.API 单表-便捷 方法 举例

  1. like 条件

 var res1 = await Conn.QueryListAsync<Agent>(it => it.Name.Contains("陈"));

    以 MySQL 为例,生成 SQL 如下:

 select *
from `agent`
where `Name` like CONCAT('%',?Name_1,'%');

   2. not like 条件

 var res1 = await Conn.QueryListAsync<Agent>(it => !it.Name.Contains("刘"));

    以 MySQL 为例,生成 SQL 如下:

 select *
from `agent`
where `Name` not like CONCAT('%',?Name_1,'%');

三.API 单表-完整 方法 举例

  1. like 条件

             var res1 = await Conn
.Queryer<Agent>()
.Where(it => it.CreatedOn >= Convert.ToDateTime("2018-08-23 13:36:58").AddDays(-))
.And(it => it.PathId.Contains("~00-d-3-1-"))
.QueryPagingAsync(, );

    以 MySQL 为例,生成 SQL 如下:

 -- 总数
select count(*)
from `agent`
where `CreatedOn`>=?CreatedOn_1
and `PathId` like CONCAT('%',?PathId_2,'%'); -- 分页数据
select *
from `agent`
where `CreatedOn`>=?CreatedOn_1
and `PathId` like CONCAT('%',?PathId_2,'%')
order by `Id` desc
limit 0,10;

  2. not like 条件

             var res1 = await Conn
.Queryer<Agent>()
.Where(it => !it.PathId.Contains("~00-d-3-1-"))
.QueryPagingAsync(, );

    以 MySQL 为例,生成 SQL 如下:

 -- 总数
select count(*)
from `agent`
where `PathId` not like CONCAT('%',?PathId_1,'%'); -- 分页数据
select *
from `agent`
where `PathId` not like CONCAT('%',?PathId_1,'%')
order by `Id` desc
limit 0,10;

四.API 多表连接-完整 方法 举例

  1. like 条件

             var res1 = await Conn
.Queryer(out Agent agent1, out AgentInventoryRecord record1)
.From(() => agent1)
.InnerJoin(() => record1)
.On(() => agent1.Id == record1.AgentId)
.Where(() => agent1.Name.Contains("陈"))
.QueryListAsync<AgentInventoryRecord>();

    以 MySQL 为例,生成 SQL 如下:

 select record1.`*`
from `agent` as agent1
inner join `agentinventoryrecord` as record1
on agent1.`Id`=record1.`AgentId`
where agent1.`Name` like CONCAT('%',?Name_4,'%');

  2. not like 条件

             var res1 = await Conn
.Queryer(out Agent agent1, out AgentInventoryRecord record1)
.From(() => agent1)
.InnerJoin(() => record1)
.On(() => agent1.Id == record1.AgentId)
.Where(() => !agent1.Name.Contains("陈"))
.QueryListAsync<AgentInventoryRecord>();

    以 MySQL 为例,生成 SQL 如下:

 select record1.`*`
from `agent` as agent1
inner join `agentinventoryrecord` as record1
on agent1.`Id`=record1.`AgentId`
where agent1.`Name` not like CONCAT('%',?Name_4,'%');

五.String.StartsWith() 举例

  1. like 条件

             var res13 = await Conn
.Queryer(out Agent agent13, out AgentInventoryRecord record13)
.From(() => agent13)
.InnerJoin(() => record13)
.On(() => agent13.Id == record13.AgentId)
.Where(() => agent13.Name.StartsWith("张"))
.QueryListAsync<Agent>();

    以 MySQL 为例,生成 SQL 如下,其中 ?Name_4 的值会自动生成 '张%'

 select agent13.`*`
from `agent` as agent13
inner join `agentinventoryrecord` as record13
on agent13.`Id`=record13.`AgentId`
where agent13.`Name` like ?Name_4;

  2. not like 条件

             var res22 = await Conn
.Queryer(out Agent agent22, out AgentInventoryRecord record22)
.From(() => agent22)
.InnerJoin(() => record22)
.On(() => agent22.Id == record22.AgentId)
.Where(() => !agent22.Name.StartsWith("张"))
.QueryListAsync<Agent>();

    以 MySQL 为例,生成 SQL 如下,其中 ?Name_4 的值会自动生成 '张%'

 select agent22.`*`
from `agent` as agent22
inner join `agentinventoryrecord` as record22
on agent22.`Id`=record22.`AgentId`
where agent22.`Name` not like ?Name_4;

六.String.EndsWith() 举例

  1. like 条件

             var res13 = await Conn
.Queryer(out Agent agent13, out AgentInventoryRecord record13)
.From(() => agent13)
.InnerJoin(() => record13)
.On(() => agent13.Id == record13.AgentId)
.Where(() => agent13.Name.EndsWith("华"))
.QueryListAsync<Agent>();

    以 MySQL 为例,生成 SQL 如下,其中 ?Name_4 的值会自动生成 '%华'

 select agent13.`*`
from `agent` as agent13
inner join `agentinventoryrecord` as record13
on agent13.`Id`=record13.`AgentId`
where agent13.`Name` like ?Name_4;

  2. not like 条件

             var res22 = await Conn
.Queryer(out Agent agent22, out AgentInventoryRecord record22)
.From(() => agent22)
.InnerJoin(() => record22)
.On(() => agent22.Id == record22.AgentId)
.Where(() => !agent22.Name.EndsWith("华"))
.QueryListAsync<Agent>();

    以 MySQL 为例,生成 SQL 如下,其中 ?Name_4 的值会自动生成 '%华'

 select agent22.`*`
from `agent` as agent22
inner join `agentinventoryrecord` as record22
on agent22.`Id`=record22.`AgentId`
where agent22.`Name` not like ?Name_4;

七.MySQL 通配符 %(百分号) 、 _(下划线) 举例

  1. %

 var res5 = await Conn.QueryListAsync<Agent>(it => it.Name.Contains("陈%"));

    以 MySQL 为例,生成 SQL 如下,其中 like 的时候 会保留 原状 按自定义的 格式串 查询,?Name_1 的值为 '陈%'

 select *
from `agent`
where `Name` like ?Name_1;

  2. _

 var res6 = await Conn.QueryListAsync<Agent>(it => it.Name.Contains("王_"));

    以 MySQL 为例,生成 SQL 如下,其中 like 的时候 会保留 原状 按自己定义的 格式串 查询,?Name_1 的值为 '王_'

 select *
from `agent`
where `Name` like ?Name_1;

八.MySQL 通配符转义 /%(百分号转义)、/_(下划线转义) 举例

  1. /%

             var res7 = await Conn
.Queryer<Agent>()
.Where(it => it.Name.Contains("刘/%_"))
.And(it => it.Id == resx4.Id)
.And(it => it.Name.Contains("%华"))
.And(it => it.Name.Contains("%/%%"))
.QueryListAsync();

    以 MySQL 为例,生成 SQL 如下,其中 ?Name_1 的值为 '刘/%_' ,% 会按其 字面义 在DB中匹配查询

 select *
from `agent`
where `Name` like ?Name_1 escape '/'
and `Id`=?Id_2
and `Name` like ?Name_3
and `Name` like ?Name_4 escape '/';

  2. /_

             var res8 = await Conn.QueryListAsync<Agent>(it => it.Name.Contains("何/__"));

    以 MySQL 为例,生成 SQL 如下,其中 ?Name_1 的值为 '何/__' ,_ 会按其 字面义 在DB中匹配查询

 select *
from `agent`
where `Name` like ?Name_1 escape '/';

                                         蒙

                                    2019-02-18 14:45 周一

                                    2019-02-24 17:50 周日

                                    2019-04-13 00:29 周六

MyDAL - like && not like 条件 使用的更多相关文章

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

    索引: 目录索引 一.API 列表 C# 代码中 接口 IList.Contains() 方法生成 SQL 对应的 in(val1,val2,... ...) 如:.Queryer<Agent& ...

  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. Docker最全教程之使用TeamCity来完成内部CI、CD流程(十六)

    本篇教程主要讲解基于容器服务搭建TeamCity服务,并且完成内部项目的CI流程配置.教程中也分享了一个简单的CI.CD流程,仅作探讨.不过由于篇幅有限,完整的DevOps,我们后续独立探讨. 为了降 ...

  2. linux文件权限总结(创建root不可以删除文件、只可追加的日志文件等)

    文件类型 对于文件和目录的访问权力是根据读访问,写访问,和执行访问来定义的. 我们来看一下 ls 命令的输出结果 [root@iZ28dr6w0qvZ test]# ls -l 总用量 72 -rw- ...

  3. vue 设计一个倒计时秒杀的组件

    简介: 倒计时秒杀组件在电商网站中层出不穷  不过思路万变不离其踪,我自己根据其他资料设计了一个vue版的 核心思路:1.时间不能是本地客户端的时间  必须是服务器的时间这里用一个settimeout ...

  4. Dotspatial 要素重叠部分去除

    private void toolStripButton32_Click(object sender, EventArgs e) { /重叠部分去除操作——测试成功 if (mapMain.Layer ...

  5. helm 持久化部署ingres

    Ingress 是一种 Kubernetes 资源,也是将 Kubernetes 集群内服务暴露到外部的一种方式.本文将讲一讲如何用 Helm 在 Kubernetes 集群中部署 Ingress,并 ...

  6. 如何检测或判断一个文件或字节流(无BOM)是什么编码类型

    前言: 昨天,在文章:终于等到你:CYQ.Data V5系列 (ORM数据层,支持.NET Core)最新版本开源了 中, 不小心看到一条留言: 然后就去该地址看了一下,这一看,顺带折腾了一天. 今天 ...

  7. for in 使用

    // JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. 易于人阅读和编写. var json = { "id": 1, "n ...

  8. 用ASP.NET Core 2.1 建立规范的 REST API -- 保护API和其它

    本文介绍如何保护API,无需看前边文章也能明白吧. 预备知识: http://www.cnblogs.com/cgzl/p/9010978.html http://www.cnblogs.com/cg ...

  9. 细说mysql索引

    本文从如何建立mysql索引以及介绍mysql的索引类型,再讲mysql索引的利与弊,以及建立索引时需要注意的地方 首先:先假设有一张表,表的数据有10W条数据,其中有一条数据是nickname='c ...

  10. 使用nvm管理node不同版本,安装,环境配置,切换不同版本的node版本

    文章包含以下内容: 一.下载地址 二.nvm-noinstall.zip安装 三.nvm-setup.zip安装 四.测试安装以及使用 一.下载地址 https://github.com/coreyb ...