设为首页 加入收藏

TOP

MyDAL - like && not like 条件 使用(一)
2019-09-17 18:01:30 】 浏览:38
Tags:MyDAL like not 条件 使用

索引:

目录索引

一.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 条件

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

    以 MySQL 为例,生成 SQL 如下:

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

   2. not like 条件

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

    以 MySQL 为例,生成 SQL 如下:

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

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

  1. like 条件

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

    以 MySQL 为例,生成 SQL 如下:

 1 -- 总数
 2 select  count(*) 
 3 from `agent`
 4 where  `CreatedOn`>=?CreatedOn_1
 5     and  `PathId` like  CONCAT('%',?PathId_2,'%');
 6 
 7 -- 分页数据
 8 select *
 9 from `agent`
10 where  `CreatedOn`>=?CreatedOn_1
11     and  `PathId` like  CONCAT('%',?PathId_2,'%')
12 order by `Id` desc
13 limit 0,10;

  2. not like 条件

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

    以 MySQL 为例,生成 SQL 如下:

 1 -- 总数
 2 select  count(*) 
 3 from `agent`
 4 where  `PathId` not like  CONCAT('%',?PathId_1,'%');
 5 
 6 -- 分页数据
 7 select *
 8 from `agent`
 9 where  `PathId` not like  CONCAT('%',?PathId_1,'%')
10 order by `Id` desc
11 limit 0,10;

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

  1. like 条件

1             var res1 = await Conn
2                 .Queryer(out Agent agent1, out AgentInventoryRecord record1)
3                 .From(() => agent1)
4                     .InnerJoin(() => record1)
5                         .On(() => agent1.Id == record1.AgentId)
6                 .Where(() => agent1.Name.Contains(""))
7                 .QueryListAsync<AgentInventoryRecord>();

    以 MySQL 为例,生成 SQL 如下:

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

  2. not like 条件

1
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Entity Farmework领域建模方式 3.. 下一篇8天入门docker系列 —— 第三天 ..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目