索引:

目录索引

一.API 列表

  1.Where

    .Where(Func<M, bool> func)

      如: .Where( it => (it.Prop1>=条件1 && it.Prop2<=条件2) || it.Prop3==条件3 ) 此类写法,

        用在 Deleter/Updater/Queryer(单表) 中.

    .Where(Func<bool>)

      如: .Where( () => m1.PropX==条件1 || m2.PropY>条件2 && m3.PropZ<条件3 ) 此类写法,用在 Queryer(多表) 中.

  2.And

    .And(Func<M, bool> func)  .Where(Func<M, bool> func) .

    .And(Func<bool>)  .Where(Func<bool>) .

  3.Or

    .Or(Func<M, bool> func)  .Where(Func<M, bool> func) .

    .Or(Func<bool>)  .Where(Func<bool>) .

  注: where and or 三个 api 是可以组合使用的,我在这里将他们的关系 处理为 sql 中同样的用法,

    即一个 sql 查询中只可以点出一个where,但可以点出多个and 或 or

    如:  ...Where(xxx).And(yyy).Or(mmm).And(zzz)..... .

二.使用举例

  1.删除数据

             var path = "~00-c-1-2-1-1-1-1-1-4-1-1-1-4-1-2-1-7";
var level = ;
// where and
var res3 = await Conn
.Deleter<Agent>()
.Where(it => it.PathId == path)
.And(it => it.AgentLevel == (AgentLevel)level)
.DeleteAsync();

     以 MySQL 为例,生成 SQL 如下:

 delete
from `Agent`
where `PathId`=?PathId_1
and `AgentLevel`=?AgentLevel_2 ;

  2.更新数据

             var res8 = await Conn
.Updater<Agent>()
.Set(it => it.AgentLevel, AgentLevel.NewCustomer)
.Where(it => it.Id == Guid.Parse("0014f62d-2a96-4b5b-b4bd-01654438e3d4"))
.UpdateAsync();

    以 MySQL 为例,生成 SQL 如下:

 update `Agent`
set `AgentLevel`=?AgentLevel_1
where `Id`=?Id_2 ;

  3.单表 查询数据

             var guid4 = Guid.Parse("000cecd5-56dc-4085-804b-0165443bdf5d");
var pathId4 = "~00-d-3-2-1-c-2-f-4-3-1-2-4";
var level4 = AgentLevel.Customer;
var res4 = await Conn
.Queryer<Agent>()
.Where(it => it.Id == guid4 && it.AgentLevel==level4 && it.PathId == pathId4)
.QueryListAsync();

    以 MySQL 为例,生成 SQL 如下:

 select *
from `Agent`
where (( `Id`=?Id_3 && `AgentLevel`=?AgentLevel_4 ) && `PathId`=?PathId_5 )
order by `CreatedOn` desc ;

  4.多表连接 查询数据

             var res6 = await Conn
.Queryer(out Agent agent6, out AgentInventoryRecord record6)
.From(() => agent6)
.InnerJoin(() => record6)
.On(() => agent6.Id == record6.AgentId)
.Where(() => agent6.Id == guid6)
.QueryOneAsync<Agent>();

    以 MySQL 为例,生成 SQL 如下:

 select       agent6.`*`
from `Agent` as agent6
inner join AgentInventoryRecord as record6
on agent6.`Id`=record6.`AgentId`
where agent6.`Id`=?Id_4
order by agent6.`CreatedOn` desc ;

                                         蒙

                                    2018-11-18 16:32 周日

                                    2018-12-13 15:27 周四

                                    2018-12-30 11:15 周日

                                    2019-02-24 17:45 周日

                                    2019-04-12 18:04 周五

MyDAL - .Where() & .And() & .Or() 使用的更多相关文章

  1. MyDAL - 引用类型对象 .DeepClone() 深度克隆[深度复制] 工具 使用

    索引: 目录索引 一.API 列表 .DeepClone() 用于 Model / Entity / ... ... 等引用类型对象的深度克隆 特性说明 1.不需要对对象做任何特殊处理,直接 .Dee ...

  2. MyDAL - 组件适用范围说明

    索引: 目录索引 一.组件特性简介: 1.MSIL 底层代码采用 System.Reflection.Emit.Lightweight 类库使用 IL 的方式处理 Model 组装,性能刚刚的~ 2. ...

  3. MyDAL - 快速使用

    索引: 目录索引 一.安装 在 VS 中执行一下 package 命令: PM> Install-Package MyDAL 二.API-快速使用 1.命名空间,只需: using MyDAL; ...

  4. MyDAL - .Where() 之 .WhereSegment 根据条件 动态设置 Select查询条件 使用

    索引: 目录索引 一.API 列表 1.WhereSegment 属性,指示 根据条件 动态拼接 where 查询过滤条件 见如下示例. 二.API 单表-完整 方法 举例 // 上下文条件 变量 v ...

  5. MyDAL - .UpdateAsync() 之 .SetSegment 根据条件 动态设置 要更新的字段 使用

    索引: 目录索引 一.API 列表 1.SetSegment 属性,指示 根据条件 动态拼接 要修改的字段 见如下示例. 二.API 单表-完整 方法 举例 // update 要赋值的变量 var ...

  6. MyDAL - .UpdateAsync() 之 .Set() 使用

    索引: 目录索引 一.API 列表 1.Set<M, F>(Expression<Func<M, F>> propertyFunc, F newVal) 如: .S ...

  7. MyDAL - .UpdateAsync() 使用

    索引: 目录索引 一.API 列表 1.UpdateAsync() 用于 单表 更新操作 二.API 单表-便捷 方法 举例-01 var pk1 = Guid.Parse("8f2cbb6 ...

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

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

  9. MyDAL - like && not like 条件 使用

    索引: 目录索引 一.API 列表 C# 代码中 String.Contains("conditionStr") 生成 SQL 对应的 like '%conditionStr%' ...

  10. MyDAL - is null && is not null 条件 使用

    索引: 目录索引 一.API 列表 C# 代码中 instance.property == null 生成 SQL 对应的 is null : 如:.Queryer<Agent>() .. ...

随机推荐

  1. Visual Studio 2019 发布活动 - 2019 年 4 月 2 日

    Visual Studio 2019 发布活动 2019 年 4 月 2 日,星期二 | 上午 9:00 (PT) 围观: https://visualstudio.microsoft.com/zh- ...

  2. geodocker-geomesa安装指南

        最近研究geopyspark原本以为大数据研究能告一段落,因为...     开玩笑的,还要一起建设社会主义呢!! 背景     geotrellis作为一个处理遥感数据的框架,对于遥感数据支 ...

  3. sql 语句 获取某张表某列字段最短的某几行数据

    sql 语句 获取某张表某列字段最短的某几行数据 SELECT C_name,C_code FROM Catalog where LEN(C_code)=LEN((SELECT top 1 C_cod ...

  4. Windows2008安装组件命令行工具ServerManagerCmd用法介绍

    转自:http://blog.sina.com.cn/s/blog_537de4b5010128al.html Windows2008 安装组件服务等内容比原来复杂的多,用鼠标点来点去,既繁琐也缓慢, ...

  5. Windows Server 2016-Powershell之客户端加域

    将本地计算机添加到域或工作组,可通过Add-Computer命令操作,具体信息如下: 语法: Add-Computer [-DomainName] <String> [-ComputerN ...

  6. July 09th, 2018. Monday, Week 28th.

    Happiness is an inside job. 自内寻找,才能找到幸福. From William Arthur Ward. Nobody wants to suffer, and we al ...

  7. vscode创建net core控制台程序

    vscode近来深受的开发人员的喜爱.在下的前端同事们也纷纷使用vscode.在下就想了我等后端程序员也可以用vscode写C#代码.毕竟是从宇宙第一IDE  ----Visual Studio衍生的 ...

  8. 【Android Studio安装部署系列】二十八、Android Studio查看其它APP的布局结构

    概述 日常使用别家的APP过程中,会遇到一些比较好看的布局,这时候我们就想学习一下别人的布局结构,以便参考. (1)手机连接电脑.设置手机为USB调试模式 参考<[Android Studio安 ...

  9. ZooKeeper 02 - ZooKeeper集群的节点为什么是奇数个

    目录 1 关于节点个数的说明 2 ZooKeeper集群的容错数 3 ZooKeeper集群可用的标准 4 为什么不能是偶数个节点 4.1 防止由脑裂造成的集群不可用 4.2 奇数个节点更省资源 4. ...

  10. Asp.Net Core 轻松学-利用 Swagger 自动生成接口文档

    前言     目前市场上主流的开发模式,几乎清一色的前后端分离方式,作为服务端开发人员,我们有义务提供给各个客户端良好的开发文档,以方便对接,减少沟通时间,提高开发效率:对于开发人员来说,编写接口文档 ...