索引:

目录索引

一.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. ajax请求window.open()被拦截

    项目使用ajax post后根据返回的success,需要打开一个新页面,使用window.open发现谷歌浏览器直接被拦截. 后来了解发现该操作并不是用户主动触发的,所以它认为这是不安全的就拦截了, ...

  2. 工厂方法模式(Factory Method Pattern)

    工厂方法模式概述 工厂方法模式是为了弥补简单工厂模式的不足并且继承它的优点而延生出的一种设计模式,属于GoF中的一种.它能更好的符合开闭原则的要求. 定义:定义了一个用于创建对象的接口,但是让子类决定 ...

  3. 前端笔记之CSS(下)浮动&BFC&定位&Hack

    一.浮动 1.1 各个语言的主要知识点 HTML:标签语义化(那么怎么样布局才是合理的?没有绝对的对和错) CSS: 样式: 布局: 标准流(标准文档流.普通文档流):盒子模型(width/heigh ...

  4. 泛微oa几个常用的js

    泛微OA,常用JS 为满足一些简单需求,我从网上借鉴了大量的代码,其中几个是非常好用的. (1).取值判断 通过jQuery('#field1234').val()取字段的值,field1234对应字 ...

  5. Unity项目开发过程中常见的问题,你遇到过吗?

    最近看到有朋友问一个unity游戏开发团队,需要掌握哪些知识之类的问题.事实上Unity引擎是一个很灵活的引擎,根据团队开发游戏类型的不同,对人员的要求也有差异,所以不能一概而论.但是,一些在Unit ...

  6. CTF取证方法大汇总,建议收藏!

    站在巨人的肩头才会看见更远的世界,这是一篇来自技术牛人的神总结,运用多年实战经验总结的CTF取证方法,全面细致,通俗易懂,掌握了这个技能定会让你在CTF路上少走很多弯路,不看真的会后悔! 本篇文章大约 ...

  7. 分布式架构原理解析,Java开发必修课

    1. 分布式术语 1.1. 异常 服务器宕机 内存错误.服务器停电等都会导致服务器宕机,此时节点无法正常工作,称为不可用. 服务器宕机会导致节点失去所有内存信息,因此需要将内存信息保存到持久化介质上. ...

  8. spring boot 2.0 集成 shiro 和 pac4j cas单点登录

    新开的项目,果断使用  spring boot  最新版本  2.0.3 ,免得后期升级坑太多,前期把雷先排了. 由于对 shiro 比较熟,故使用 shiro 来做权限控制.同时已经存在了 cas  ...

  9. Window10升级遇到大坑错误代码:0xc000000e完美解决方案

    昨天忽然升级了,然后并没有立即重启更新,因为但是正在工作所以等下班回到家后就是一直提示:文件:\Windows\system32\winload.efi 错误代码:0xc000000e!!! 如下图所 ...

  10. css垂直居中方法总结

    在网页布局中,我们往往会遇到下图所示的场景,让小图标和文字对齐 可能有的小伙伴会说,这个简单,直接给小图标设置左浮动来实现. 这样做是可以的,但不推荐,毕竟浮动是会影响布局的,能少用还是少用. 以前遇 ...