Bitter.Core 在聚联/分页聚联查询的时候,采用原生的MSSQL, MYSQL 语句查询,做过复杂高级项目的人知道,原生的聚合查询代码执行效率更高,更快,更容易书写,开发量最少。
借助原生的MSSQL,MYSQL 客户端工具,将聚合查询的SELECT 语句写好,直接扔进Bitter ORM 框架就行了。
业务层只关心写好相对应的 SELECT SQL 语句. 如下代码示例:
#region //聚联条件分页查询 var type = 1; //非关键代码,用于下面演示代码用 var Score=100;var studentname = "H"; //非关键代码,用于下面演示代码用var sql = @"SELECT score.FScore,student.FName as studentName,class.FName as className,grade.FName as gradeName FROM dbo.t_StudentScore scoreLEFT JOIN dbo.t_student student ON score.FStudentId = student.FIDLEFT JOIN dbo.t_class class ON student.FClassId=class.FIDLEFT JOIN dbo.t_Grade grade ON grade.FID=class.FGradeId";PageQuery pq = new PageQuery(sql, null);pq.Where("1=1");if (type == 1){pq.Where("score.FScore>60 ");}if (type == 2){ pq.Where("score.FScore>60 and score.FScore<80 ");}if (type == 3){ pq.Where("score.FScore==@ParmeScore",new {ParmeScore=Score}});}if (!string.IsNullOrEmpty(studentname)){pq.Where(" student.FName like '%' + @FScoreName + '%'",new {FScoreName=studentname});}//通过ThenAsc 方法指定字段排序pq.ThenASC("score.FScore ");//通过ThenDESC 方法指定字段排序pq.ThenDESC("student.FName");//自己直接指定排序字段和排序关键词pq.OrderBy("student.FAddTime desc");//分页指定 Skip: 当前页,Take :每页数量pq.Skip(1).Take(10);var dt = pq.ToDataTable(); //获取数据var studentscount = pq.Count(); //获取当前条件下的数量
没有评论:
发表评论