public void 单表分页查询测试MS() { LockPers lpmodel = new LockPers(); lpmodel.Name = "%蛋蛋%"; lpmodel.IsDel = false; Expression <Func <LockPers, bool> > where = PredicateBuilder.WhereStart <LockPers>(); where = where.And((lpw) => lpw.Name.Contains(lpmodel.Name)); where = where.And((lpw) => lpw.IsDel == lpmodel.IsDel); DapperSqlMaker <LockPers> query = LockDapperUtilmssql <LockPers> .Selec() .RowRumberOrderBy(lp => new { lp.EditCount, lp.Name }) .Column() // lp => new { lp.Id, lp.InsertTime, lp.EditCount, lp.IsDel }) // null查询所有字段 .From() .Where(where); //lp => lp.Name == lpmodel.Name && lp.IsDel == lpmodel.IsDel ) //.Order(lp => new { lp.EditCount, lp.Name }); // .ExecuteQuery(); var result = query.ExecuteQuery(); WriteJson(result); // 查询结果 Tuple <StringBuilder, DynamicParameters> resultsqlparams = query.RawSqlParams(); Console.WriteLine(resultsqlparams.Item1.ToString()); // sql foreach (var name in resultsqlparams.Item2.ParameterNames) { WriteJson(name + " -- " + resultsqlparams.Item2.Get <object>(name)); // 参数 -- 值 } int page = 1, rows = 3, records; var result2 = query.LoadPagems(page, rows, out records); WriteJson(result2); // 查询结果 }
public void 四表联表分页测试MS() { LockPers lpmodel = new LockPers() { Name = "%蛋蛋%", IsDel = false }; Users umodel = new Users() { UserName = "******" }; SynNote snmodel = new SynNote() { Name = "%木头%" }; Expression <Func <LockPers_ms, Users_ms, SynNote_ms, SynNote_ms, bool> > where = PredicateBuilder.WhereStart <LockPers_ms, Users_ms, SynNote_ms, SynNote_ms>(); where = where.And((lpw, uw, sn, snn) => lpw.Name.Contains(lpmodel.Name)); where = where.And((lpw, uw, sn, snn) => lpw.IsDel == lpmodel.IsDel); where = where.And((lpw, uw, sn, snn) => uw.UserName == umodel.UserName); where = where.And((lpw, uw, sn, snn) => sn.Name.Contains(snmodel.Name)); // SM.LimitCount, DapperSqlMaker <LockPers_ms, Users_ms, SynNote_ms, SynNote_ms> query = LockDapperUtilmssql <LockPers_ms, Users_ms, SynNote_ms, SynNote_ms> .Selec() .RowRumberOrderBy((lp, u, s, sn) => new { lp.Id, a = u.Id }) .Column((lp, u, s, sn) => new { SM.LimitCount, lp.Id, lp.InsertTime, lp.EditCount, lp.IsDel, u.UserName, s.Content, s.Name })//null查询所有字段 .FromJoin(JoinType.Left, (lpp, uu, snn, snnn) => uu.Id == lpp.UserId , JoinType.Inner, (lpp, uu, snn, snnn) => uu.Id == snn.UserId && snn.Id == snn.UserId , JoinType.Inner, (lpp, uu, snn, snnn) => snnn.Id == snn.UserId) .Where(where); //(lpp, uu, snn, snnn) => uu.Id == snn.UserId && snnn.Id == snn.UserId)//) // .Order((lp, w, sn, snn) => new { lp.EditCount, lp.Name, sn.Content }); Tuple <StringBuilder, DynamicParameters> resultsqlparams = query.RawSqlParams(); WriteSqlParams(resultsqlparams); var result = query.ExecuteQuery(); WriteJson(result); // 查询结果 int page = 2, rows = 2, records; var result2 = query.LoadPagems(page, rows, out records); WriteJson(result2); // 查询结果 }
public void 双表联表分页测试MS() { LockPers lpmodel = new LockPers() { Name = "%蛋蛋%", IsDel = false }; Users umodel = new Users() { UserName = "******" }; Expression <Func <LockPers, Users, bool> > where = PredicateBuilder.WhereStart <LockPers, Users>(); where = where.And((lpw, uw) => lpw.Name.Contains(lpmodel.Name)); where = where.And((lpw, uw) => lpw.IsDel == lpmodel.IsDel); where = where.And((lpw, uw) => uw.UserName == umodel.UserName); DapperSqlMaker <LockPers, Users> query = LockDapperUtilmssql <LockPers, Users> .Selec() .RowRumberOrderBy((lp, u) => new { lp.EditCount, lp.Name }) .Column((lp, u) => new { lp.Id, lp.InsertTime, lp.EditCount, lp.IsDel, u.UserName }) //null查询所有字段 .FromJoin(JoinType.Left, (lpp, uu) => uu.Id == lpp.UserId) .Where(where); //(lp, u) => lp.Name == lpmodel.Name && lp.IsDel == lpmodel.IsDel || u.UserName == umodel.UserName ) //.Order((lp, w) => new { lp.EditCount, lp.Name }); // .ExecuteQuery(); var result = query.ExecuteQuery(); WriteJson(result); // 查询结果 Tuple <StringBuilder, DynamicParameters> resultsqlparams = query.RawSqlParams(); WriteSqlParams(resultsqlparams); int page = 1, rows = 3, records; var result2 = query.LoadPagems(page, rows, out records); WriteJson(result2); // 查询结果 }