一: 单表模型驱动查询 如下示例代码演示:

// 根据ID 查询:
var studentquery = db.FindQuery<TStudentInfo>().QueryById(12);
#region 根据条件全量查询  学生姓名为 HJB 的同学
BList<TStudentInfo> students = db.FindQuery<TStudentInfo>().Where(p => p.FName == "HJB").Find(); // 根据条件批量查询 学生姓名为 HJB 的同学
TStudentInfo student_1 = db.FindQuery<TStudentInfo>().Where(p => p.FName == "HJB").Find().FirstOrDefault(); //此FirstOrDefault 重构过,为安全模式,数据库如果查不到数据,返回为空对象,避免返回 NULL.
if (student_1.FID > 0) //说明查询到数据
{ }
#endregion
#region 根据条件全量查询 ,查询到年龄大于等于15 岁的学生 

students = db.FindQuery<TStudentInfo>().Where(p => p.FAage >=15).Find();

#endregion
#region 根据条件全量查询 ,查询到年龄大于等于15 岁 并且 年龄 小于 17岁 的学生

students = db.FindQuery<TStudentInfo>().Where(p => p.FAage >= 15&&p.FAage<17).Find();
//上面的查询也可以写如下方式
students = db.FindQuery<TStudentInfo>().Where(p => p.FAage >= 15).Where(p => p.FAage < 17).Find(); //多级 Where 查询 #endregion
#region 根据条件全量查询 ,查询到年龄<>15

students = db.FindQuery<TStudentInfo>().Where(p => p.FAage != 15).Find();

#endregion
#region 根据条件全量查询,查询到名字包含 "H" 的学生 

students = db.FindQuery<TStudentInfo>().Where(p => p.FName.Contains("H")).Find(); //Contains 运行最终 Sql 为 : '%H%',暂时不支持 'H%','%H'

#endregion
#region 根据条件全量查询,多级 Where  查询

var studentquery = db.FindQuery<TStudentInfo>().Where(p => p.FName.Contains("H")); //Contains 运行最终 Sql 为 : '%H%',暂时不支持 'H%','%H'
studentquery.Where(p=>p.FAage>15);
students = studentquery.Find(); #endregion

二:高级查询直接SQL语句查询(非分页)

#region 高级查询直接SQL语句查询(非分页)
//查出分数>=90分的学生姓名以及具体学分 DataTable dt= db.FindQuery(
@"SELECT score.FScore,student.FName as studentNameFROM t_StudentScore score
LEFT JOIN t_student student ON score.FStudentId = student.FID
WHERE score.FScore>=@score
", new { score = 90 }).Find();
#endregion

三:单表模型驱动查询数量:

#region 根据条件全量查询 ,查询到年龄<>15 的总数量

var count = db.FindQuery<TStudentInfo>().Where(p => p.FAage != 15).FindCount();

#endregion

四: 单表模型驱动查询 排序:

1:正序
#region  ASC  正序 

students = db.FindQuery<TStudentInfo>().Where(p=>p.FAage>15).ThenAsc(p=>p.FAddTime).Find();

#endregion
2:正序
#region  DESC  正序 

students = db.FindQuery<TStudentInfo>().Where(p=>p.FAage>15).ThenDesc(p=>p.FAddTime).Find();

#endregion
3:多级排序(DESC)
#region  DESC  多级正序 

students = db.FindQuery<TStudentInfo>().Where(p=>p.FAage>15).ThenDesc(p=>p.FAage).ThenDesc(p=>p.FAddTime).Find();

#endregion
4:多级排序(ASC)
#region  ASC  多级正序 

students = db.FindQuery<TStudentInfo>().Where(p=>p.FAage>15).ThenAsc(p=>p.FAage).ThenAsc(p=>p.FAddTime).Find();

#endregion
5:多级正序倒序混排(ASC-DESC)
#region  (ASC-DESC)  多级正序倒序混排

students = db.FindQuery<TStudentInfo>().Where(p => p.FAage > 15).ThenAsc(p => p.FAage).ThenDesc(p => p.FAddTime).Find();

#endregion

五:单表模型驱动查询--只查询符合条件的前 N 条数据:

#region  (ASC-DESC)  多级正序倒序混排

students = db.FindQuery<TStudentInfo>().Where(p => p.FAage > 15).ThenAsc(p => p.FAage).ThenDesc(p => p.FAddTime).SetSize(10).Find(); //后面的 SetSize(N)  方法指定了需要查询的前 N 条数量

#endregion

六:单表模型驱动查询--只查询符合条件的前 N 条数据,并且只返回具体的列(FAage,FName):

#region  单表模型驱动查询--只查询符合条件的前 N 条数据,并且只返回具体的列(FAage,FName):

students = db.FindQuery<TStudentInfo>().Where(p => p.FAage > 15).ThenAsc(p => p.FAage).ThenDesc(p => p.FAddTime).SetSize(10).Select(c=>new object[] { c.FAage,c.FName}).Find(); //后面的 Select(columns)  方法指定了需要查询的列
students = db.FindQuery<TStudentInfo>().Where(p => p.FAage > 15).ThenAsc(p => p.FAage).ThenDesc(p => p.FAddTime).SetSize(10).Select(c => new List<object>{ c.FAage, c.FName }).Find(); //后面的 Select(columns) 方法指定了需要查询的列 #endregion

最新文章

  1. Centos 7 minimal install 无网络无ifconfig的解决
  2. js事件模型与自定义事件
  3. js undefine,null 和NaN
  4. 两个oracle之间建立db link
  5. java中产生对象的两种方式
  6. C#并行编程--命令式数据并行(Parallel.Invoke)---与匿名函数一起理解(转载整理)
  7. 模拟游客一天的生活与旅游java程序代写源码
  8. javscript面试题(一)
  9. 大白话Vue源码系列目录
  10. Android studio签名与代码混淆
  11. 一键安装Cloud Torrent
  12. TestNG Suite 运行出现中文乱码如何解决
  13. springboot+thymeleaf+springbootJPA实现一个简单的增删改查
  14. bayer格式
  15. django CBV和FBV写法总结
  16. Guava CharMatcher
  17. [Timer]应用层实现sleep
  18. struts2 自带的 token防止表单重复提交拦截器
  19. Jquery 对比 Javascript
  20. php实现图形计算器

热门文章

  1. C# 托管与非托管类型 堆和栈 值类型与引用类型 装箱与拆箱
  2. Core3.0全局捕获异常
  3. kickstart+pxe部署
  4. 在.NET Core 中收集数据的几种方式
  5. 查看权限详情 将部门大类单据整合,将子类单据id去重合并
  6. easyui中开始时间小于结束时间 不然无法点击
  7. 从最长公共子序列问题理解动态规划算法(DP)
  8. python +pycharm+selenium 环境搭建
  9. 前端中的 IoC 理念
  10. 第14章节 BJROBOT karto 算法构建地图【ROS全开源阿克曼转向智能网联无人驾驶车】