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

MyDAL - in && not in 条件 使用

程序员文章站 2024-01-26 15:08:28
索引: 目录索引 一.API 列表 C# 代码中 接口 IList.Contains() 方法生成 SQL 对应的 in(val1,val2,... ...) 如:.Queryer() ... ... .Where(it => new AgentLevel?[] { AgentLeve ......

索引:

目录索引

一.api 列表

  c# 代码中 接口 ilist.contains() 方法生成 sql 对应的 in(val1,val2,... ...)

     如:.queryer<agent>()

      ... ...

      .where(it => new agentlevel?[] { agentlevel.cityagent, agentlevel.distiagent }.contains(it.agentlevel))

      ... ... 用于 单表 in 条件

      .queryer(out agent agent, out agentinventoryrecord record)

      ... ...

      .where(() => !new agentlevel?[] { agentlevel.cityagent, agentlevel.distiagent }.contains(agent.agentlevel))

      ... ... 用于 多表连接 in 条件

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

  1. in 条件

1 var res2 = await conn
2     .querylistasync<agent>(it => new list<agentlevel?> { agentlevel.cityagent, agentlevel.distiagent }.contains(it.agentlevel));

    生成 sql 如下

1 select *
2 from `agent`
3 where  `agentlevel`  in (@agentlevel_2,@agentlevel_3);

  2. not in 条件

1 var res2 = await conn
2     .querylistasync<agent>(it => !new list<agentlevel?> { agentlevel.cityagent, agentlevel.distiagent }.contains(it.agentlevel));

    生成 sql 如下

1 select *
2 from `agent`
3 where  `agentlevel`  not in (@agentlevel_2,@agentlevel_3);

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

  1. in 条件

1             var res5 = await conn
2                 .queryer<agent>()
3                 .where(it => new list<string> { "黄银凤", "刘建芬" }.contains(it.name))
4                 .querylistasync();

    生成 sql 如下

1 select *
2 from `agent`
3 where  `name`  in (@name_2,@name_3);

  2. not in 条件

1             var res5 = await conn
2                 .queryer<agent>()
3                 .where(it => !new list<string> { "黄银凤", "刘建芬" }.contains(it.name))
4                 .querylistasync();

    生成 sql 如下

1 select *
2 from `agent`
3 where  `name`  not in (@name_2,@name_3);

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

  1. in 条件

1             var res1 = await conn
2                 .queryer(out agent agent, out agentinventoryrecord record)
3                 .from(() => agent)
4                     .innerjoin(() => record)
5                         .on(() => agent.id == record.agentid)
6                 .where(() => new agentlevel?[] { agentlevel.cityagent, agentlevel.distiagent }.contains(agent.agentlevel))
7                 .querylistasync<agent>();

    生成 sql 如下

1 select agent.`*`
2 from `agent` as agent 
3     inner join `agentinventoryrecord` as record
4         on agent.`id`=record.`agentid`
5 where  agent.`agentlevel`  in (@agentlevel_5,@agentlevel_6);

  2. not in 条件

1             var res1 = await conn
2                 .queryer(out agent agent, out agentinventoryrecord record)
3                 .from(() => agent)
4                     .innerjoin(() => record)
5                         .on(() => agent.id == record.agentid)
6                 .where(() => !new agentlevel?[] { agentlevel.cityagent, agentlevel.distiagent }.contains(agent.agentlevel))
7                 .querylistasync<agent>();

    生成 sql 如下

1 select agent.`*`
2 from `agent` as agent 
3     inner join `agentinventoryrecord` as record
4         on agent.`id`=record.`agentid`
5 where  agent.`agentlevel`  not in (@agentlevel_5,@agentlevel_6);

五.数组 array 举例

  1. in 条件

 1             var enumarray = new agentlevel?[]
 2             {
 3                 agentlevel.cityagent,
 4                 agentlevel.distiagent
 5             };
 6 
 7             var res12 = await conn
 8                 .queryer<agent>()
 9                 .where(it => enumarray.contains(it.agentlevel))
10                 .querylistasync();

    生成 sql 如下

1 select *
2 from `agent`
3 where  `agentlevel`  in (@agentlevel_2,@agentlevel_3);

  2. not in 条件

 

1             var res1 = await conn
2                 .queryer<agent>()
3                 .where(it => !new agentlevel?[] { agentlevel.cityagent, agentlevel.distiagent }.contains(it.agentlevel))
4                 .querylistasync();

    生成 sql 如下

1 select *
2 from `agent`
3 where  `agentlevel`  not in (@agentlevel_2,@agentlevel_3);

六.列表 list<t> 举例

  1. in 条件

 1             var enums = new list<agentlevel?>
 2             {
 3                 agentlevel.cityagent,
 4                 agentlevel.distiagent
 5             };
 6 
 7             var res1 = await conn
 8                 .queryer<agent>()
 9                 .where(it => enums.contains(it.agentlevel))
10                 .querylistasync();

    生成 sql 如下

1 select *
2 from `agent`
3 where  `agentlevel`  in (@agentlevel_2,@agentlevel_3);

  2. not in 条件

1             var res1 = await conn
2                 .queryer<agent>()
3                 .where(it => !new list<agentlevel?> { agentlevel.cityagent, agentlevel.distiagent }.contains(it.agentlevel))
4                 .querylistasync();

    生成 sql 如下

1 select *
2 from `agent`
3 where  `agentlevel`  not in (@agentlevel_2,@agentlevel_3);

 

 

 

                                         蒙

                                    2019-03-04 22:10 周一