索引:

目录索引

一.API 列表

  .QueryOneAsync()

  .QueryOneAsync<M>()

    如: .QueryOneAsync<Agent>() , 用于 单表/多表连接 查询.

  .QueryOneAsync<VM>()

    如: .QueryOneAsync<AgentVM>() , 用于 单表 查询.

  .QueryOneAsync<T>(Expression<Func<M, T>> columnMapFunc)

    如: .QueryOneAsync<Guid>(it => it.Id) , 用于 单表 单列 查询.

    或者:

        .QueryOneAsync<AgentVM>(it => new AgentVM
                   {
                      XXXX = it.Name,
                      YYYY = it.PathId
                   })    , 用于 单表 多列 查询.

  .QueryOneAsync<T>(Expression<Func<T>> columnMapFunc)

    如: .Queryer(out Agent agent, out AgentInventoryRecord agentRecord)

      ......

      .QueryOneAsync<string>(() => agent.Name)

      用于 多表连接 单列 查询.

    或者:

      .Queryer(out Agent agent2, out AgentInventoryRecord record2)

      ......

      .QueryOneAsync(() => new AgentVM
                   {
                      nn = agent2.PathId,
                      yy = record2.Id,
                      xx = agent2.Id,
                      zz = agent2.Name,
                      mm = record2.LockedCount
                     })  , 用于 多表连接 多列 查询.

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

  1. 单表 单列 便捷方法    

             var pk = Guid.Parse("8f2cbb64-8356-4482-88ee-016558c05b2d");
var date= DateTime.Parse("2018-08-20 19:12:05.933786"); var res3 = await Conn
5          .QueryOneAsync<AlipayPaymentRecord, Guid>(it => it.Id == pk && it.CreatedOn == date,it=>it.Id);

    以 MySQL 为例,生成 SQL 如下:

 select `Id`
from `AlipayPaymentRecord`
where ( `Id`=?Id_2 && `CreatedOn`=?CreatedOn_3)
limit 0,1;

  2. 单表 多列 便捷方法

             var pk = Guid.Parse("8f2cbb64-8356-4482-88ee-016558c05b2d");
var date= DateTime.Parse("2018-08-20 19:12:05.933786"); var res4 = await Conn
           .QueryOneAsync<AlipayPaymentRecord, AlipayPaymentRecordVM>(it => it.Id == pk && it.CreatedOn == date,
it => new AlipayPaymentRecordVM
{
Id = it.Id,
TotalAmount = it.TotalAmount,
Description = it.Description
});

    以 MySQL 为例,生成 SQL 如下:

 select     `Id` as Id,
`TotalAmount` as TotalAmount,
`Description` as Description
from `AlipayPaymentRecord`
where ( `Id`=?Id_2 && `CreatedOn`=?CreatedOn_3)
limit 0,1;

  3. 单表 单条 VM 便捷方法

             var pk = Guid.Parse("8f2cbb64-8356-4482-88ee-016558c05b2d");
var date = DateTime.Parse("2018-08-20 19:12:05.933786"); var res5 = await Conn
5          .QueryOneAsync<AlipayPaymentRecord, AlipayPaymentRecordVM>(it => it.Id == pk && it.CreatedOn == date);

    以 MySQL 为例,生成 SQL 如下:

 select     `Id`,
`CreatedOn`,
`TotalAmount`,
`Description`,
`CanceledOn`
from `AlipayPaymentRecord`
where ( `Id`=?Id_2 && `CreatedOn`=?CreatedOn_3)
limit 0,1;

  4. 单表 单条 M 便捷方法

             var pk = Guid.Parse("8f2cbb64-8356-4482-88ee-016558c05b2d");
var date = DateTime.Parse("2018-08-20 19:12:05.933786"); var res6 = await Conn
5          .QueryOneAsync<AlipayPaymentRecord>(it => it.Id == pk && it.CreatedOn == date);

    以 MySQL 为例,生成 SQL 如下:

 select *
from `AlipayPaymentRecord`
where ( `Id`=?Id_2 && `CreatedOn`=?CreatedOn_3)
limit 0,1;

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

  1. 单表 单列 完整方法

             var time1 = DateTime.Parse("2018-08-16 19:22:01.716307");

             var res1 = await Conn
.Queryer<Agent>()
.Where(it => it.CreatedOn == time1)
.QueryOneAsync<Guid>(it => it.Id);

    以 MySQL 为例,生成 SQL 如下:

 select `Id`
from `Agent`
where `CreatedOn`=?CreatedOn_1
limit 0,1;

  2.单表 多列 完整方法

             var res3 = await Conn
.Queryer<Agent>()
.Where(it => it.Id == Guid.Parse("000c1569-a6f7-4140-89a7-0165443b5a4b"))
.QueryOneAsync<AgentVM>(it => new AgentVM
{
XXXX = it.Name,
YYYY = it.PathId
});

    以 MySQL 为例,生成 SQL 如下:

 select     `Name` as XXXX,
`PathId` as YYYY
from `Agent`
where `Id`=?Id_1
limit 0,1;

  3.单表 单条 VM 完整方法

             var res1 = await Conn
.Queryer<Agent>()
.Where(it => it.Id == Guid.Parse("000c1569-a6f7-4140-89a7-0165443b5a4b"))
.QueryOneAsync<AgentVM>();

    以 MySQL 为例,生成 SQL 如下:

 select     `Id`,
`CreatedOn`,
`UserId`,
`PathId`,
`Name`,
`Phone`
from `Agent`
where `Id`=?Id_1
limit 0,1;

  4.单表 单条 M 完整方法

             var res1 = await Conn
.Queryer<BodyFitRecord>()
.Where(it => it.Id == Guid.Parse("1fbd8a41-c75b-45c0-9186-016544284e2e"))
.QueryOneAsync();

    以 MySQL 为例,生成 SQL 如下:

 select *
from `BodyFitRecord`
where `Id`=?Id_1
limit 0,1;

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

  1.多表连接 单列 完整方法

             var res1 = await Conn
.Queryer(out Agent agent, out AgentInventoryRecord agentRecord)
.From(() => agent)
.InnerJoin(() => agentRecord)
.On(() => agent.Id == agentRecord.AgentId)
.Where(() => agent.AgentLevel == AgentLevel.DistiAgent)
.QueryOneAsync<string>(() => agent.Name);

    以 MySQL 为例,生成 SQL 如下:

 select agent.`Name`
from `Agent` as agent
inner join AgentInventoryRecord as agentRecord
on agent.`Id`=agentRecord.`AgentId`
where agent.`AgentLevel`=?AgentLevel_4
limit 0,1;

  2.多表连接 多列 完整方法

             var guid2 = Guid.Parse("544b9053-322e-4857-89a0-0165443dcbef");

             var res2 = await Conn
.Queryer(out Agent agent2, out AgentInventoryRecord record2)
.From(() => agent2)
.InnerJoin(() => record2)
.On(() => agent2.Id == record2.AgentId)
.Where(() => agent2.Id == guid2)
.QueryOneAsync(() => new AgentVM
{
nn = agent2.PathId,
yy = record2.Id,
xx = agent2.Id,
zz = agent2.Name,
mm = record2.LockedCount
});

    以 MySQL 为例,生成 SQL 如下:

 select     agent2.`PathId` as nn,
record2.`Id` as yy,
agent2.`Id` as xx,
agent2.`Name` as zz,
record2.`LockedCount` as mm
from `Agent` as agent2
inner join AgentInventoryRecord as record2
on agent2.`Id`=record2.`AgentId`
where agent2.`Id`=?Id_4
limit 0,1;

  3.多表连接 单条 M 完整方法

             var guid6 = Guid.Parse("544b9053-322e-4857-89a0-0165443dcbef");

             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
limit 0,1;

                                         蒙

                                    2018-12-13 14:35 周四

                                    2018-12-30 11:25 周日

                                    2019-02-24 17:03 周日

                                    2019-04-12 19:32 周五

MyDAL - .QueryOneAsync() 使用的更多相关文章

  1. MyDAL - 快速使用

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

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

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

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

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

  4. MyDAL - .Where() & .And() & .Or() 使用

    索引: 目录索引 一.API 列表 1.Where .Where(Func<M, bool> func) 如: .Where( it => (it.Prop1>=条件1 &am ...

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

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

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

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

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

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

  8. MyDAL - .UpdateAsync() 使用

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

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

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

随机推荐

  1. asp.net core 系列之webapi集成EFCore的简单操作教程

    因为官网asp.net core webapi教程部分,给出的是使用内存中的数据即 UseInMemoryDatabase 的方式, 这里记录一下,使用SQL Server数据库的方式即 UseSql ...

  2. 第1章 发现端点(Discovery Endpoint) - IdentityModel 中文文档(v1.0.0)

    OpenID Connect发现端点的客户端库作为httpclient的扩展方法提供.该GetDiscoveryDocumentAsync方法返回一个DiscoveryResponse对象,该对象具有 ...

  3. Java 学习笔记 Junit4单元测试使用

    Junit使用 1.导入Junit包 到官网下载个Junit4.12.jar文件,放在lib目录 或者在类的空白处打@Test,之后按下alt+enter,选择添加Junit4依赖 之后就会弹出一个窗 ...

  4. Center a website:网页居中

    inside the <body> tags, using a "wrapper" div to control the whole section. HTML: &l ...

  5. 如何通过免费开源ERP Odoo建立你的团队, 销售过程和目标

    这种快速的一步一步的指南将引导您完成Odoo CRM, 帮助您轻松处理您的销售渠道, 时刻从线索到客户管理您的销售渠道. 配置 从 Odoo初始化后,生成你的数据库, 选择CRM 作为第一个app安装 ...

  6. PostgreSQL(PostGIS)安装和入门的若干问题

    1. 装完PostgreSQL后记得打开pgAdmin4启动一下服务器和启动一下数据库,否则PostGIS装不上. 2. pgAdmin4是网页,而3是客户端,当然都可以在File - Prefere ...

  7. cesium 之地图贴地量算工具效果篇(附源码下载)

    前言 cesium 官网的api文档介绍地址cesium官网api,里面详细的介绍 cesium 各个类的介绍,还有就是在线例子:cesium 官网在线例子,这个也是学习 cesium 的好素材. 内 ...

  8. android消息处理源码分析

    一.简介消息处理机制主要涉及到这几个类:1.Looper2.MessageQueue3.Message4.Handler 二.源码分析 Looper.class的关键源码: //保存Looper对象, ...

  9. [.net core] 在 Windows 中运行出现 WinHttpException: The parameter is incorrect

    有一个 web 服务一直跑在 docker 中,今天需要在 Windows 上部署一个备份版本,于是,签出源代码,编译,运行.结果抛出 500 ,日志中有如下记录: System.Net.Http.H ...

  10. Java笔试题库之选题题篇【141-210题】

    141.Struts框架可以支持以下哪种程序开发语言? A.C B.C++ C.Java D.C# 解答:C 142.在Servlet处理请求的方式为. A.以进程的方式 B.以程序的方式 C.以线程 ...