索引:html
目錄索引數組
一.API 列表es5
C# 代碼中 接口 IList.Contains() 方法生成 SQL 對應的 in(val1,val2,... ...)spa
如:.Queryer<Agent>()code
... ...htm
.Where(it => new AgentLevel?[] { AgentLevel.CityAgent, AgentLevel.DistiAgent }.Contains(it.AgentLevel))blog
... ... 用於 單表 in 條件索引
.Queryer(out Agent agent, out AgentInventoryRecord record)接口
... ...get
.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));
以 MySQL 爲例,生成 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));
以 MySQL 爲例,生成 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();
以 MySQL 爲例,生成 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();
以 MySQL 爲例,生成 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>();
以 MySQL 爲例,生成 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>();
以 MySQL 爲例,生成 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();
以 MySQL 爲例,生成 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();
以 MySQL 爲例,生成 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();
以 MySQL 爲例,生成 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();
以 MySQL 爲例,生成 SQL 以下:
1 select * 2 from `agent` 3 where `AgentLevel` not in (?AgentLevel_2,?AgentLevel_3);
蒙
2019-03-04 22:10 週一
2019-04-13 20:28 週六