Dapper 链式查询 扩展

Dapper 链式查询扩展 DapperSqlMaker   

Github地址https://github.com/mumumutou/DapperSqlMaker

Demo:

查询       TestsDapperSqlMaker\DapperSqlMaker.Test\ SelectDapperSqlMakerTest.cs

添加       TestsDapperSqlMaker\DapperSqlMaker.Test\  InsertDapperSqlMakerTest.cs

更新       TestsDapperSqlMaker\DapperSqlMaker.Test\  UpdateDapperSqlMakerTest.cs

删除       TestsDapperSqlMaker\DapperSqlMaker.Test\  DeleteDapperSqlMakerTest.cs

上下文类   TestsDapperSqlMaker\DbDapperSqlMaker\  LockDapperUtilsqlite.cs

简单栗子: 1.查询-联表查询,分页 

 

1 [Test] 2 public void 三表联表分页测试() 3 { 4 LockPers lpmodel = new LockPers() { Name = "%蛋蛋%", IsDel = false}; 5 Users umodel = new Users() { UserName = "jiaojiao" }; 6 SynNote snmodel = new SynNote() { Name = "%木头%" }; 7 Expression<Func<LockPers, Users, SynNote, bool>> where = PredicateBuilder.WhereStart<LockPers, Users, SynNote>(); 8 where = where.And((lpw, uw, sn) => lpw.Name.Contains(lpmodel.Name)); 9 where = where.And((lpw, uw, sn) => lpw.IsDel == lpmodel.IsDel); 10 where = where.And((lpw, uw, sn) => uw.UserName == umodel.UserName); 11 where = where.And((lpw, uw, sn) => sn.Name.Contains(snmodel.Name)); 12 13 DapperSqlMaker<LockPers, Users, SynNote> query = LockDapperUtilsqlite<LockPers, Users, SynNote> 14 .Selec() 15 .Column((lp, u, s) => // null) //查询所有字段 16 new { lp.Id, lp.InsertTime, lp.EditCount, lp.IsDel, u.UserName, s.Content, s.Name }) 17 .FromJoin(JoinType.Left, (lpp, uu, snn) => uu.Id == lpp.UserId 18 , JoinType.Inner, (lpp, uu, snn) => uu.Id == snn.UserId) 19 .Where(where) 20 .Order((lp, w, sn) => new { lp.EditCount, lp.Name, sn.Content }); 21 22 var result = query.ExcuteSelect(); //1. 执行查询 23 WriteJson(result); // 打印查询结果 24 25 Tuple<StringBuilder, DynamicParameters> resultsqlparams = query.RawSqlParams(); 26 WriteSqlParams(resultsqlparams); // 打印生成sql和参数 27 28 int page = 2, rows = 3, records; 29 var result2 = query.LoadPagelt(page, rows, out records); //2. 分页查询 30 WriteJson(result2); // 查询结果 31 }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wppwjs.html