索引:
一.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 条件
var res2 = await Conn
.QueryListAsync<Agent>(it => new List<AgentLevel?> { AgentLevel.CityAgent, AgentLevel.DistiAgent }.Contains(it.AgentLevel));
以 MySQL 为例,生成 SQL 如下:
select *
from `agent`
where `AgentLevel` in (?AgentLevel_2,?AgentLevel_3);
2. not in 条件
var res2 = await Conn
.QueryListAsync<Agent>(it => !new List<AgentLevel?> { AgentLevel.CityAgent, AgentLevel.DistiAgent }.Contains(it.AgentLevel));
以 MySQL 为例,生成 SQL 如下:
select *
from `agent`
where `AgentLevel` not in (?AgentLevel_2,?AgentLevel_3);
三.API 单表-完整 方法 举例
1. in 条件
var res5 = await Conn
.Queryer<Agent>()
.Where(it => new List<string> { "黄银凤", "刘建芬" }.Contains(it.Name))
.QueryListAsync();
以 MySQL 为例,生成 SQL 如下:
select *
from `agent`
where `Name` in (?Name_2,?Name_3);
2. not in 条件
var res5 = await Conn
.Queryer<Agent>()
.Where(it => !new List<string> { "黄银凤", "刘建芬" }.Contains(it.Name))
.QueryListAsync();
以 MySQL 为例,生成 SQL 如下:
select *
from `agent`
where `Name` not in (?Name_2,?Name_3);
四.API 多表连接-完整 方法 举例
1. in 条件
var res1 = await Conn
.Queryer(out Agent agent, out AgentInventoryRecord record)
.From(() => agent)
.InnerJoin(() => record)
.On(() => agent.Id == record.AgentId)
.Where(() => new AgentLevel?[] { AgentLevel.CityAgent, AgentLevel.DistiAgent }.Contains(agent.AgentLevel))
.QueryListAsync<Agent>();
以 MySQL 为例,生成 SQL 如下:
select agent.`*`
from `agent` as agent
inner join `agentinventoryrecord` as record
on agent.`Id`=record.`AgentId`
where agent.`AgentLevel` in (?AgentLevel_5,?AgentLevel_6);
2. not in 条件
var res1 = await Conn
.Queryer(out Agent agent, out AgentInventoryRecord record)
.From(() => agent)
.InnerJoin(() => record)
.On(() => agent.Id == record.AgentId)
.Where(() => !new AgentLevel?[] { AgentLevel.CityAgent, AgentLevel.DistiAgent }.Contains(agent.AgentLevel))
.QueryListAsync<Agent>();
以 MySQL 为例,生成 SQL 如下:
select agent.`*`
from `agent` as agent
inner join `agentinventoryrecord` as record
on agent.`Id`=record.`AgentId`
where agent.`AgentLevel` not in (?AgentLevel_5,?AgentLevel_6);
五.数组 Array 举例
1. in 条件
var enumArray = new AgentLevel?[]
{
AgentLevel.CityAgent,
AgentLevel.DistiAgent
}; var res12 = await Conn
.Queryer<Agent>()
.Where(it => enumArray.Contains(it.AgentLevel))
.QueryListAsync();
以 MySQL 为例,生成 SQL 如下:
select *
from `agent`
where `AgentLevel` in (?AgentLevel_2,?AgentLevel_3);
2. not in 条件
var res1 = await Conn
.Queryer<Agent>()
.Where(it => !new AgentLevel?[] { AgentLevel.CityAgent, AgentLevel.DistiAgent }.Contains(it.AgentLevel))
.QueryListAsync();
以 MySQL 为例,生成 SQL 如下:
select *
from `agent`
where `AgentLevel` not in (?AgentLevel_2,?AgentLevel_3);
六.列表 List<T> 举例
1. in 条件
var enums = new List<AgentLevel?>
{
AgentLevel.CityAgent,
AgentLevel.DistiAgent
}; var res1 = await Conn
.Queryer<Agent>()
.Where(it => enums.Contains(it.AgentLevel))
.QueryListAsync();
以 MySQL 为例,生成 SQL 如下:
select *
from `agent`
where `AgentLevel` in (?AgentLevel_2,?AgentLevel_3);
2. not in 条件
var res1 = await Conn
.Queryer<Agent>()
.Where(it => !new List<AgentLevel?> { AgentLevel.CityAgent, AgentLevel.DistiAgent }.Contains(it.AgentLevel))
.QueryListAsync();
以 MySQL 为例,生成 SQL 如下:
select *
from `agent`
where `AgentLevel` not in (?AgentLevel_2,?AgentLevel_3);
蒙
2019-03-04 22:10 周一
2019-04-13 20:28 周六