索引:
一.API 列表
.SelectOne()
.SelectOne<M>()
如: .SelectOne<Agent>() , 用于 单表/多表连接 查询.
.SelectOne<VM>()
如: .SelectOne<AgentVM>() , 用于 单表 查询.
.SelectOne<T>(Expression<Func<M, T>> columnMapFunc)
如: .SelectOne<Guid>(it => it.Id) , 用于 单表 单列 查询.
或者:
.SelectOne<AgentVM>(it => new AgentVM
{
XXXX = it.Name,
YYYY = it.PathId
}) , 用于 单表 多列 查询.
.SelectOne<T>(Expression<Func<T>> columnMapFunc)
如: .Selecter(out Agent agent, out AgentInventoryRecord agentRecord)
......
.SelectOne<string>(() => agent.Name)
用于 多表连接 单列 查询.
或者:
.Selecter(out Agent agent2, out AgentInventoryRecord record2)
......
.SelectOne(() => new AgentVM
{
nn = agent2.PathId,
yy = record2.Id,
xx = agent2.Id,
zz = agent2.Name,
mm = record2.LockedCount
}) , 用于 多表连接 多列 查询.
二.API 单表-便捷 方法 举例
1. 单表 单列 便捷方法
1 var pk = Guid.Parse("8f2cbb64-8356-4482-88ee-016558c05b2d"); 2 var date= DateTime.Parse("2018-08-20 19:12:05.933786"); 3 4 var res3 = await Conn
5 .SelectOne<AlipayPaymentRecord, Guid>(it => it.Id == pk && it.CreatedOn == date,it=>it.Id);
以 MySQL 为例,生成 SQL 如下:
1 select `Id` 2 from `AlipayPaymentRecord` 3 where ( `Id`=?Id_2 && `CreatedOn`=?CreatedOn_3) 4 limit 0,1;
2. 单表 多列 便捷方法
1 var pk = Guid.Parse("8f2cbb64-8356-4482-88ee-016558c05b2d"); 2 var date= DateTime.Parse("2018-08-20 19:12:05.933786"); 3 4 var res4 = await Conn
.SelectOne<AlipayPaymentRecord, AlipayPaymentRecordVM>(it => it.Id == pk && it.CreatedOn == date, 5 it => new AlipayPaymentRecordVM 6 { 7 Id = it.Id, 8 TotalAmount = it.TotalAmount, 9 Description = it.Description 10 });
以 MySQL 为例,生成 SQL 如下:
1 select `Id` as Id, 2 `TotalAmount` as TotalAmount, 3 `Description` as Description 4 from `AlipayPaymentRecord` 5 where ( `Id`=?Id_2 && `CreatedOn`=?CreatedOn_3) 6 limit 0,1;
3. 单表 单条 VM 便捷方法
1 var pk = Guid.Parse("8f2cbb64-8356-4482-88ee-016558c05b2d"); 2 var date = DateTime.Parse("2018-08-20 19:12:05.933786"); 3 4 var res5 = await Conn
5 .SelectOne<AlipayPaymentRecord, AlipayPaymentRecordVM>(it => it.Id == pk && it.CreatedOn == date);
以 MySQL 为例,生成 SQL 如下:
1 select `Id`, 2 `CreatedOn`, 3 `TotalAmount`, 4 `Description`, 5 `CanceledOn` 6 from `AlipayPaymentRecord` 7 where ( `Id`=?Id_2 && `CreatedOn`=?CreatedOn_3) 8 limit 0,1;
4. 单表 单条 M 便捷方法
1 var pk = Guid.Parse("8f2cbb64-8356-4482-88ee-016558c05b2d"); 2 var date = DateTime.Parse("2018-08-20 19:12:05.933786"); 3 4 var res6 = await Conn
5 .SelectOne<AlipayPaymentRecord>(it => it.Id == pk && it.CreatedOn == date);
以 MySQL 为例,生成 SQL 如下:
1 select * 2 from `AlipayPaymentRecord` 3 where ( `Id`=?Id_2 && `CreatedOn`=?CreatedOn_3) 4 limit 0,1;
三.API 单表-完整 方法 举例
1. 单表 单列 完整方法
1 var time1 = DateTime.Parse("2018-08-16 19:22:01.716307"); 2 3 var res1 = await Conn 4 .Selecter<Agent>() 5 .Where(it => it.CreatedOn == time1) 6 .SelectOne<Guid>(it => it.Id);
以 MySQL 为例,生成 SQL 如下:
1 select `Id` 2 from `Agent` 3 where `CreatedOn`=?CreatedOn_1 4 limit 0,1;
2.单表 多列 完整方法
1 var res3 = await Conn 2 .Selecter<Agent>() 3 .Where(it => it.Id == Guid.Parse("000c1569-a6f7-4140-89a7-0165443b5a4b")) 4 .SelectOne<AgentVM>(it => new AgentVM 5 { 6 XXXX = it.Name, 7 YYYY = it.PathId 8 });
以 MySQL 为例,生成 SQL 如下:
1 select `Name` as XXXX, 2 `PathId` as YYYY 3 from `Agent` 4 where `Id`=?Id_1 5 limit 0,1;
3.单表 单条 VM 完整方法
1 var res1 = await Conn 2 .Selecter<Agent>() 3 .Where(it => it.Id == Guid.Parse("000c1569-a6f7-4140-89a7-0165443b5a4b")) 4 .SelectOne<AgentVM>();
以 MySQL 为例,生成 SQL 如下:
1 select `Id`, 2 `CreatedOn`, 3 `UserId`, 4 `PathId`, 5 `Name`, 6 `Phone` 7 from `Agent` 8 where `Id`=?Id_1 9 limit 0,1;
4.单表 单条 M 完整方法
1 var res1 = await Conn 2 .Selecter<BodyFitRecord>() 3 .Where(it => it.Id == Guid.Parse("1fbd8a41-c75b-45c0-9186-016544284e2e")) 4 .SelectOne();
以 MySQL 为例,生成 SQL 如下:
1 select * 2 from `BodyFitRecord` 3 where `Id`=?Id_1 4 limit 0,1;
四.API 多表连接-完整 方法 举例
1.多表连接 单列 完整方法
1 var res1 = await Conn 2 .Selecter(out Agent agent, out AgentInventoryRecord agentRecord) 3 .From(() => agent) 4 .InnerJoin(() => agentRecord) 5 .On(() => agent.Id == agentRecord.AgentId) 6 .Where(() => agent.AgentLevel == AgentLevel.DistiAgent) 7 .SelectOne<string>(() => agent.Name);
以 MySQL 为例,生成 SQL 如下:
1 select agent.`Name` 2 from `Agent` as agent 3 inner join AgentInventoryRecord as agentRecord 4 on agent.`Id`=agentRecord.`AgentId` 5 where agent.`AgentLevel`=?AgentLevel_4 6 limit 0,1;
2.多表连接 多列 完整方法
1 var guid2 = Guid.Parse("544b9053-322e-4857-89a0-0165443dcbef"); 2 3 var res2 = await Conn 4 .Selecter(out Agent agent2, out AgentInventoryRecord record2) 5 .From(() => agent2) 6 .InnerJoin(() => record2) 7 .On(() => agent2.Id == record2.AgentId) 8 .Where(() => agent2.Id == guid2) 9 .SelectOne(() => new AgentVM 10 { 11 nn = agent2.PathId, 12 yy = record2.Id, 13 xx = agent2.Id, 14 zz = agent2.Name, 15 mm = record2.LockedCount 16 });
以 MySQL 为例,生成 SQL 如下:
1 select agent2.`PathId` as nn, 2 record2.`Id` as yy, 3 agent2.`Id` as xx, 4 agent2.`Name` as zz, 5 record2.`LockedCount` as mm 6 from `Agent` as agent2 7 inner join AgentInventoryRecord as record2 8 on agent2.`Id`=record2.`AgentId` 9 where agent2.`Id`=?Id_4 10 limit 0,1;
3.多表连接 单条 M 完整方法
1 var guid6 = Guid.Parse("544b9053-322e-4857-89a0-0165443dcbef"); 2 3 var res6 = await Conn 4 .Selecter(out Agent agent6, out AgentInventoryRecord record6) 5 .From(() => agent6) 6 .InnerJoin(() => record6) 7 .On(() => agent6.Id == record6.AgentId) 8 .Where(() => agent6.Id == guid6) 9 .SelectOne<Agent>();
以 MySQL 为例,生成 SQL 如下:
1 select agent6.`*` 2 from `Agent` as agent6 3 inner join AgentInventoryRecord as record6 4 on agent6.`Id`=record6.`AgentId` 5 where agent6.`Id`=?Id_4 6 limit 0,1;
2018-12-30 11:25 周日
2019-04-12 19:32 周五