mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-02 03:13:58 +08:00
-
This commit is contained in:
@@ -47,15 +47,15 @@ namespace OrmTest.UnitTest
|
||||
|
||||
|
||||
#region sql and parameters validate
|
||||
var ss0 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||
var t1 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||
JoinType.Inner,st.Id==sc.Id
|
||||
}).GroupBy(st => st.Id).Having(sc => NBORM.AggregateAvg(sc.Id) == 1).Select(st => new { avgId = NBORM.AggregateAvg(st.Id) }).ToSql();
|
||||
base.Check("SELECT AVG([st].[Id]) AS [avgId] FROM [Student] st Inner JOIN School sc ON ( [st].[Id] = [sc].[Id] ) GROUP BY [st].[Id] HAVING (AVG([sc].[Id]) = @Const0 ) ",
|
||||
}).GroupBy(st => st.Id).Having(st => NBORM.AggregateAvg(st.Id) == 1).Select(st => new { avgId = NBORM.AggregateAvg(st.Id) }).ToSql();
|
||||
base.Check("SELECT AVG([st].[ID]) AS [avgId] FROM [STudent] st Inner JOIN School sc ON ( [st].[ID] = [sc].[Id] ) GROUP BY [st].[ID] HAVING (AVG([st].[ID]) = @Const0 ) ",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@Const0",1)
|
||||
}
|
||||
,
|
||||
ss0.Key, ss0.Value, " ss0 Error");
|
||||
t1.Key, t1.Value, " select t1 Error");
|
||||
|
||||
|
||||
var ss1 = db.Queryable<School, School>((st, st2) => new object[] {
|
||||
|
||||
@@ -30,74 +30,74 @@ namespace OrmTest.UnitTest
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
var s1 = db.Queryable<Student>().ToSql();
|
||||
base.Check("SELECT [Id],[SchoolId],[Name],[CreateTime] FROM [Student]", null, s1.Key, null, "s1 Error");
|
||||
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent]", null, s1.Key, null, "single s1 Error");
|
||||
|
||||
var s2 = db.Queryable<Student>().With(SqlWith.NoLock).ToSql();
|
||||
base.Check("SELECT [Id],[SchoolId],[Name],[CreateTime] FROM [Student] WITH(NOLOCK)", null, s2.Key, null, "s2 Error");
|
||||
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WITH(NOLOCK)", null, s2.Key, null, "single s2 Error");
|
||||
|
||||
var s3 = db.Queryable<Student>().OrderBy(it=>it.Id).ToSql();
|
||||
base.Check("SELECT [Id],[SchoolId],[Name],[CreateTime] FROM [Student] ORDER BY [Id] ASC", null, s3.Key, null, "s3 Error");
|
||||
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] ORDER BY [ID] ASC", null, s3.Key, null, "single s3 Error");
|
||||
|
||||
var s4 = db.Queryable<Student>().OrderBy(it => it.Id).Take(3).ToSql();
|
||||
base.Check(@"WITH PageTable AS(
|
||||
SELECT [Id],[SchoolId],[Name],[CreateTime] FROM [Student]
|
||||
SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent]
|
||||
)
|
||||
SELECT * FROM (SELECT *,ROW_NUMBER() OVER(ORDER BY [Id] ASC) AS RowIndex FROM PageTable ) T WHERE RowIndex BETWEEN 1 AND 3", null, s4.Key, null, "s4 Error");
|
||||
SELECT * FROM (SELECT *,ROW_NUMBER() OVER(ORDER BY [ID] ASC) AS RowIndex FROM PageTable ) T WHERE RowIndex BETWEEN 1 AND 3", null, s4.Key, null, "single s4 Error");
|
||||
|
||||
var s5 = db.Queryable<Student>().OrderBy(it => it.Id).Skip(3).ToSql();
|
||||
base.Check(@"WITH PageTable AS(
|
||||
SELECT [Id],[SchoolId],[Name],[CreateTime] FROM [Student]
|
||||
SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent]
|
||||
)
|
||||
SELECT * FROM (SELECT *,ROW_NUMBER() OVER(ORDER BY [Id] ASC) AS RowIndex FROM PageTable ) T WHERE RowIndex BETWEEN 4 AND 9223372036854775807", null, s5.Key,null, "s5 Error");
|
||||
SELECT * FROM (SELECT *,ROW_NUMBER() OVER(ORDER BY [ID] ASC) AS RowIndex FROM PageTable ) T WHERE RowIndex BETWEEN 4 AND 9223372036854775807", null, s5.Key,null, "single s5 Error");
|
||||
|
||||
int pageIndex = 2;
|
||||
int pageSize = 10;
|
||||
var s6 = db.Queryable<Student>().OrderBy(it => it.Id,OrderByType.Desc).Skip((pageIndex-1)*pageSize).Take(pageSize*pageIndex).ToSql();
|
||||
base.Check(@"WITH PageTable AS(
|
||||
SELECT [Id],[SchoolId],[Name],[CreateTime] FROM [Student]
|
||||
SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent]
|
||||
)
|
||||
SELECT * FROM (SELECT *,ROW_NUMBER() OVER(ORDER BY [Id] DESC) AS RowIndex FROM PageTable ) T WHERE RowIndex BETWEEN 11 AND 20", null, s6.Key, null, "s6 Error");
|
||||
SELECT * FROM (SELECT *,ROW_NUMBER() OVER(ORDER BY [ID] DESC) AS RowIndex FROM PageTable ) T WHERE RowIndex BETWEEN 11 AND 20", null, s6.Key, null, "single s6 Error");
|
||||
|
||||
|
||||
int studentCount=db.Ado.GetInt("select count(1) from Student");
|
||||
var countIsSuccess=db.Queryable<Student>().Count()== studentCount;
|
||||
if (!countIsSuccess) {
|
||||
throw new Exception("countIsSuccess Error");
|
||||
throw new Exception(" single countIsSuccess Error");
|
||||
}
|
||||
|
||||
var s7 = db.Queryable<Student>().OrderBy(it => it.Id, OrderByType.Desc).Skip((pageIndex - 1) * pageSize).Take(pageSize * pageIndex).ToPageList(pageIndex,pageSize,ref studentCount);
|
||||
countIsSuccess = studentCount == db.Queryable<Student>().OrderBy(it => it.Id, OrderByType.Desc).Skip((pageIndex - 1) * pageSize).Take(pageSize * pageIndex).Count();
|
||||
if (!countIsSuccess)
|
||||
{
|
||||
throw new Exception("s7 Error");
|
||||
throw new Exception("single s7 Error");
|
||||
}
|
||||
|
||||
int studentMin = db.Ado.GetInt("select min(id) from Student");
|
||||
var minIsSuccess = db.Queryable<Student>().Min(it=>it.Id) == studentMin;
|
||||
if (!minIsSuccess)
|
||||
{
|
||||
throw new Exception("minIsSuccess Error");
|
||||
throw new Exception("single minIsSuccess Error");
|
||||
}
|
||||
|
||||
int studentMax = db.Ado.GetInt("select max(id) from Student");
|
||||
var maxIsSuccess = db.Queryable<Student>().Max(it => it.Id) == studentMax;
|
||||
if (!maxIsSuccess)
|
||||
{
|
||||
throw new Exception("maxIsSuccess Error");
|
||||
throw new Exception("single maxIsSuccess Error");
|
||||
}
|
||||
|
||||
int studentAvg = db.Ado.GetInt("select avg(id) from Student");
|
||||
var avgIsSuccess = db.Queryable<Student>().Avg(it => it.Id) == studentAvg;
|
||||
if (!maxIsSuccess)
|
||||
{
|
||||
throw new Exception("avgIsSuccess Error");
|
||||
throw new Exception(" single avgIsSuccess Error");
|
||||
}
|
||||
|
||||
int studentSum = db.Ado.GetInt("select sum(id) from Student");
|
||||
var sumIsSuccess = db.Queryable<Student>().Sum(it => it.Id) == studentSum;
|
||||
if (!sumIsSuccess)
|
||||
{
|
||||
throw new Exception("sumIsSuccess Error");
|
||||
throw new Exception("single sumIsSuccess Error");
|
||||
}
|
||||
|
||||
var s8 = db.Queryable<Student>()
|
||||
@@ -105,11 +105,11 @@ namespace OrmTest.UnitTest
|
||||
.WhereIF(true,it=> NBORM.Contains(it.Name,"a"))
|
||||
.OrderBy(it => it.Id, OrderByType.Desc).Skip((pageIndex - 1) * pageSize).Take(pageSize * pageIndex).With(SqlWith.NoLock).ToSql();
|
||||
base.Check(@"WITH PageTable AS(
|
||||
SELECT [Id],[SchoolId],[Name],[CreateTime] FROM [Student] WITH(NOLOCK) WHERE ( [Id] = @Id0 ) AND ([Name] like '%'+@MethodConst1+'%')
|
||||
SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WITH(NOLOCK) WHERE ( [ID] = @Id0 ) AND ([Name] like '%'+@MethodConst1+'%')
|
||||
)
|
||||
SELECT * FROM (SELECT *,ROW_NUMBER() OVER(ORDER BY [Id] DESC) AS RowIndex FROM PageTable ) T WHERE RowIndex BETWEEN 11 AND 20", new List<SugarParameter>() {
|
||||
SELECT * FROM (SELECT *,ROW_NUMBER() OVER(ORDER BY [ID] DESC) AS RowIndex FROM PageTable ) T WHERE RowIndex BETWEEN 11 AND 20", new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",1),new SugarParameter("@MethodConst1","a")
|
||||
}, s8.Key, s8.Value,"s8 Error");
|
||||
}, s8.Key, s8.Value,"single s8 Error");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user