欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

MyDAL - .ListAsync() 使用

程序员文章站 2022-08-21 12:55:40
索引: 目录索引 一.API 列表 .ListAsync() .ListAsync() 如: .ListAsync() , 用于 单表/多表连接 查询. .ListAsync() 如: .ListAsync() , 用于 单 ......

索引:

目录索引

一.api 列表

  .listasync()

  .listasync<m>()

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

  .listasync<vm>()

    如: .listasync<agentvm>() , 用于 单表 查询.

  .listasync<t>(expression<func<m, t>> columnmapfunc)

    如: .listasync(it => it.name) , 用于 单表 单列 查询.

    或者: 

      .listasync(agent => new agentvm
                  {
                      xxxx = agent.name,
                      yyyy = agent.pathid
                  })  , 用于 单表 多列 查询.

  .listasync<t>(expression<func<t>> columnmapfunc)

    如:  .queryer(out agent agent1, out agentinventoryrecord record1)

      ... ...

      .listasync(() => agent1.createdon)   , 用于 多表连接 单列 查询.

    或者: .queryer(out agent agent12, out agentinventoryrecord record12)

        ... ...

       .listasync(() => new agentvm
                  {
                      nn = agent12.pathid,
                      yy = record12.id,
                      xx = agent12.id,
                      zz = agent12.name,
                      mm = record12.lockedcount
                  })  , 用于 多表连接 多列 查询.

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

  1. 单表 单列 多条 便捷方法 

1             var res7 = await conn.listasync<agent, string>(it => it.name.startswith("张"), it => it.name);

    生成的 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.listasync<alipaypaymentrecord, alipaypaymentrecordvm>(it => it.createdon >= date,
4                 it => new alipaypaymentrecordvm
5                 {
6                     totalamount = it.totalamount,
7                     description = it.description
8                 });

    生成的 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.listasync<alipaypaymentrecord, alipaypaymentrecordvm>(it => it.createdon >= date);

    生成 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.listasync<alipaypaymentrecord>(it => it.createdon >= date);

    生成 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                 .listasync(it => it.name);

    生成 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                 .listasync(agent => new agentvm
5                 {
6                     xxxx = agent.name,
7                     yyyy = agent.pathid
8                 });

    生成 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                 .listasync<agentvm>();

    生成 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                 .listasync();

    生成 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                 .listasync(() => agent1.createdon);

    生成 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                 .listasync(() => new agentvm
 8                 {
 9                     nn = agent12.pathid,
10                     yy = record12.id,
11                     xx = agent12.id,
12                     zz = agent12.name,
13                     mm = record12.lockedcount
14                 });

    生成 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                 .listasync<agentinventoryrecord>();

    生成 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 周三