MyDAL - .Where() & .And() & .Or() 使用
索引:
一.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() 使用的更多相关文章
- MyDAL - 引用类型对象 .DeepClone() 深度克隆[深度复制] 工具 使用
索引: 目录索引 一.API 列表 .DeepClone() 用于 Model / Entity / ... ... 等引用类型对象的深度克隆 特性说明 1.不需要对对象做任何特殊处理,直接 .Dee ...
- MyDAL - 组件适用范围说明
索引: 目录索引 一.组件特性简介: 1.MSIL 底层代码采用 System.Reflection.Emit.Lightweight 类库使用 IL 的方式处理 Model 组装,性能刚刚的~ 2. ...
- MyDAL - 快速使用
索引: 目录索引 一.安装 在 VS 中执行一下 package 命令: PM> Install-Package MyDAL 二.API-快速使用 1.命名空间,只需: using MyDAL; ...
- MyDAL - .Where() 之 .WhereSegment 根据条件 动态设置 Select查询条件 使用
索引: 目录索引 一.API 列表 1.WhereSegment 属性,指示 根据条件 动态拼接 where 查询过滤条件 见如下示例. 二.API 单表-完整 方法 举例 // 上下文条件 变量 v ...
- MyDAL - .UpdateAsync() 之 .SetSegment 根据条件 动态设置 要更新的字段 使用
索引: 目录索引 一.API 列表 1.SetSegment 属性,指示 根据条件 动态拼接 要修改的字段 见如下示例. 二.API 单表-完整 方法 举例 // update 要赋值的变量 var ...
- MyDAL - .UpdateAsync() 之 .Set() 使用
索引: 目录索引 一.API 列表 1.Set<M, F>(Expression<Func<M, F>> propertyFunc, F newVal) 如: .S ...
- MyDAL - .UpdateAsync() 使用
索引: 目录索引 一.API 列表 1.UpdateAsync() 用于 单表 更新操作 二.API 单表-便捷 方法 举例-01 var pk1 = Guid.Parse("8f2cbb6 ...
- MyDAL - in && not in 条件 使用
索引: 目录索引 一.API 列表 C# 代码中 接口 IList.Contains() 方法生成 SQL 对应的 in(val1,val2,... ...) 如:.Queryer<Agent& ...
- MyDAL - like && not like 条件 使用
索引: 目录索引 一.API 列表 C# 代码中 String.Contains("conditionStr") 生成 SQL 对应的 like '%conditionStr%' ...
- MyDAL - is null && is not null 条件 使用
索引: 目录索引 一.API 列表 C# 代码中 instance.property == null 生成 SQL 对应的 is null : 如:.Queryer<Agent>() .. ...
随机推荐
- Dubbo Mesh 在闲鱼生产环境中的落地实践
本文作者至简曾在 2018 QCon 上海站以<Service Mesh 的本质.价值和应用探索>为题做了一次分享,其中谈到了 Dubbo Mesh 的整体发展思路是“借力开源.反哺开源” ...
- freemarker动态生成word并将生成的word转为PDF,openoffice转换word乱码
之前项目有个需求,需要先动态生成word内容,然后再预览生成word的内容(不能修改).整理一下,方便以后使用. 网上参考了好多大神的博客.具体也忘了参考谁的了,如有侵权,请告知修改. 思路一: 将目 ...
- Loj #2192. 「SHOI2014」概率充电器
Loj #2192. 「SHOI2014」概率充电器 题目描述 著名的电子产品品牌 SHOI 刚刚发布了引领世界潮流的下一代电子产品--概率充电器: 「采用全新纳米级加工技术,实现元件与导线能否通电完 ...
- Exception: Exception caught in workbook destructor. Explicit close() may be required for workbook. 错误解决办法
# 写入表格 writer = pd.ExcelWriter('data.xlsx') new_df.to_excel(writer, sheet_name='sheet', index=True) ...
- 4.alembic数据迁移工具
alembic是用来做ORM模型与数据库的迁移与映射.alembic使用方式跟git有点类似,表现在两个方面,第一个,alemibi的所有命令都是以alembic开头: 第二,alembic的迁移文件 ...
- Elasticsearch的基本概念和指标
背景 在13年的时候,我开始负责整个公司的搜索引擎.嗯……,不是很牛的那种大项目负责人.而是整个搜索就我一个人做.哈哈. 后来跳槽之后,所经历的团队都用Elasticsearch,基本上和缓存一样,是 ...
- jenkins定位GitLab推送的最新Webhook中push event来自哪一个分支
转载请标明出处:http://www.cnblogs.com/zblade/ 一.调研目的 jenkins可以和GitLab搭档,每当GitLab上有commit的时候,都可以触发jenkins执行相 ...
- SQL优化 MySQL版 -分析explain SQL执行计划与Type级别详解
type索引类型.类型 作者 : Stanley 罗昊 [转载请注明出处和署名,谢谢!] 注:看此文章前,需要有一定的Mysql基础或观看上一篇文章,该文章传送门: https://www.cnblo ...
- 机器学习之决策树二-C4.5原理与代码实现
决策树之系列二—C4.5原理与代码实现 本文系作者原创,转载请注明出处:https://www.cnblogs.com/further-further-further/p/9435712.html I ...
- 并发系列(3)之 CLH、MCS 队列锁简介
这篇博客主要是作为 AbstractQueuedSynchronizer 的背景知识介绍:平时接触也非常的少,如果你不感兴趣可以跳过:但是了解一下能更加的清楚 AQS 的设计思路: 一.自旋锁简介 通 ...