MyDAL - .QueryListAsync() 使用

索引:html

目錄索引es5

一.API 列表spa

  .QueryListAsync()code

  .QueryListAsync<M>()htm

    如: .QueryListAsync<AgentInventoryRecord>() , 用於 單表/多表鏈接 查詢. blog

  .QueryListAsync<VM>()索引

    如: .QueryListAsync<AgentVM>() , 用於 單表 查詢.ip

  .QueryListAsync<T>(Expression<Func<M, T>> columnMapFunc)get

    如: .QueryListAsync(it => it.Name) , 用於 單表 單列 查詢.string

    或者: 

      .QueryListAsync(agent => new AgentVM
                  {
                      XXXX = agent.Name,
                      YYYY = agent.PathId
                  })  , 用於 單表 多列 查詢.

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

    如:  .Queryer(out Agent agent1, out AgentInventoryRecord record1)

      ... ...

      .QueryListAsync(() => agent1.CreatedOn)   , 用於 多表鏈接 單列 查詢.

    或者: .Queryer(out Agent agent12, out AgentInventoryRecord record12)

        ... ...

       .QueryListAsync(() => new AgentVM
                  {
                      nn = agent12.PathId,
                      yy = record12.Id,
                      xx = agent12.Id,
                      zz = agent12.Name,
                      mm = record12.LockedCount
                  })  , 用於 多表鏈接 多列 查詢.

二.API 單表-便捷 方法 舉例

  1. 單表 單列 多條 便捷方法 

1             var res7 = await Conn.QueryListAsync<Agent, string>(it => it.Name.StartsWith(""), it => it.Name);

    以 MySQL 爲例,生成 SQL 以下:

1 select `Name`
2 from `Agent`
3 where  `Name` like  ?Name_1;

  2. 單表 多列 多條 便捷方法

1        var date = DateTime.Parse("2018-08-20");
2 
3             var res3 = await Conn.QueryListAsync<AlipayPaymentRecord, AlipayPaymentRecordVM>(it => it.CreatedOn >= date,
4                 it => new AlipayPaymentRecordVM
5                 {
6                     TotalAmount = it.TotalAmount,
7                     Description = it.Description
8                 });

    以 MySQL 爲例,生成 SQL 以下:

1 select     `TotalAmount` as TotalAmount,
2         `Description` as Description
3 from `AlipayPaymentRecord`
4 where  `CreatedOn`>=?CreatedOn_1;

  3. 單表 VM 多條 便捷方法

1             var date = DateTime.Parse("2018-08-20");
2 
3             var res2 = await Conn.QueryListAsync<AlipayPaymentRecord, AlipayPaymentRecordVM>(it => it.CreatedOn >= date);

    以 MySQL 爲例,生成 SQL 以下:

1 select     `Id`,
2     `CreatedOn`,
3     `TotalAmount`,
4     `Description`,
5     `CanceledOn`
6 from `AlipayPaymentRecord`
7 where  `CreatedOn`>=?CreatedOn_1;

  4. 單表 M 多條 便捷方法

1             var date = DateTime.Parse("2018-08-20");
2 
3             var res1 = await Conn.QueryListAsync<AlipayPaymentRecord>(it => it.CreatedOn >= date);

    以 MySQL 爲例,生成 SQL 以下:

1 select *
2 from `AlipayPaymentRecord`
3 where  `CreatedOn`>=?CreatedOn_1;

三.API 單表-完整 方法 舉例

  1. 單表 單列 多條 完整方法

1             var res2 = await Conn
2                 .Queryer<Agent>()
3                 .Where(it => it.AgentLevel == AgentLevel.DistiAgent)
4                 .QueryListAsync(it => it.Name);

    以 MySQL 爲例,生成 SQL 以下:

1 select `Name`
2 from `Agent`
3 where  `AgentLevel`=?AgentLevel_1;

   2.單表 多列 多條 完整方法

1             var res5 = await Conn
2                 .Queryer<Agent>()
3                 .Where(it => it.AgentLevel == AgentLevel.DistiAgent)
4                 .QueryListAsync(agent => new AgentVM
5                 {
6                     XXXX = agent.Name,
7                     YYYY = agent.PathId
8                 });

    以 MySQL 爲例,生成 SQL 以下:

1 select     `Name` as XXXX,
2     `PathId` as YYYY
3 from `Agent`
4 where  `AgentLevel`=?AgentLevel_1;

  3.單表 VM 多條 完整方法

 1             var testQ5 = new WhereTestModel
 2             {
 3                 CreatedOn = DateTime.Now.AddDays(-30),
 4                 StartTime = WhereTest.CreatedOn,
 5                 EndTime = DateTime.Now,
 6                 AgentLevelXX = AgentLevel.DistiAgent,
 7                 ContainStr = "~00-d-3-1-"
 8             };
 9             var res5 = await Conn
10                 .Queryer<Agent>()
11                 .Where(it => it.CreatedOn >= testQ5.StartTime)
12                 .QueryListAsync<AgentVM>();

    以 MySQL 爲例,生成 SQL 以下:

1 select     `Id`,
2     `CreatedOn`,
3     `UserId`,
4     `PathId`,
5     `Name`,
6     `Phone`
7 from `Agent`
8 where  `CreatedOn`>=?CreatedOn_1;

  4. 單表 M 多條 完整方法

1             var start = WhereTest.CreatedOn.AddDays(-10);
2 
3             var res2 = await Conn
4                 .Queryer<BodyFitRecord>()
5                 .Where(it => it.CreatedOn >= start)
6                 .QueryListAsync();

    以 MySQL 爲例,生成 SQL 以下:

1 select *
2 from `BodyFitRecord`
3 where  `CreatedOn`>=?CreatedOn_1;

四.API 多表鏈接-完整 方法 舉例

  1.多表鏈接 單列 多條 完整方法

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.AgentLevel == AgentLevel.DistiAgent)
7                 .QueryListAsync(() => agent1.CreatedOn);

    以 MySQL 爲例,生成 SQL 以下:

1 select agent1.`CreatedOn`
2 from `Agent` as agent1 
3     inner join AgentInventoryRecord as record1
4         on agent1.`Id`=record1.`AgentId`
5 where  agent1.`AgentLevel`=?AgentLevel_4;

  2.多表鏈接 多列 多條 完整方法

 1             var res12 = await Conn
 2                 .Queryer(out Agent agent12, out AgentInventoryRecord record12)
 3                 .From(() => agent12)
 4                     .InnerJoin(() => record12)
 5                         .On(() => agent12.Id == record12.AgentId)
 6                 .Where(() => record12.CreatedOn >= WhereTest.CreatedOn)
 7                 .QueryListAsync(() => new AgentVM
 8                 {
 9                     nn = agent12.PathId,
10                     yy = record12.Id,
11                     xx = agent12.Id,
12                     zz = agent12.Name,
13                     mm = record12.LockedCount
14                 });

    以 MySQL 爲例,生成 SQL 以下:

1 select     agent12.`PathId` as nn,
2     record12.`Id` as yy,
3     agent12.`Id` as xx,
4     agent12.`Name` as zz,
5     record12.`LockedCount` as mm
6 from `Agent` as agent12 
7     inner join AgentInventoryRecord as record12
8         on agent12.`Id`=record12.`AgentId`
9 where  record12.`CreatedOn`>=?CreatedOn_4;

  3.多表鏈接 M 多條 完整方法

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.CreatedOn >= WhereTest.CreatedOn.AddDays(-60))   
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.`CreatedOn`>=?CreatedOn_4;

 

 

 

 

                                         蒙

                                    2018-12-26 15:25 週三

                                    2018-12-30 11:30 週日

                                    2019-04-12 23:29 週五

相關文章
相關標籤/搜索