Browse Source

-

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
0e7237e520
  1. 4
      Src/Asp.NetCore/SqlServerTest/src/MySqlTest/Demos/1_Query.cs
  2. 10
      Src/Asp.NetCore/SqlServerTest/src/MySqlTest/Demos/3_Insert.cs
  3. 2
      Src/Asp.NetCore/SqlServerTest/src/MySqlTest/Demos/7_Filter.cs
  4. 2
      Src/Asp.NetCore/SqlServerTest/src/MySqlTest/UnitTest/DataTest.cs
  5. 2
      Src/Asp.NetCore/SqlServerTest/src/MySqlTest/UnitTest/Mapping .cs
  6. 6
      Src/Asp.NetCore/SqlServerTest/src/MySqlTest/UnitTest/Query/JoinQuery.cs
  7. 6
      Src/Asp.NetCore/SqlServerTest/src/MySqlTest/UnitTest/Query/SelectQuery.cs

4
Src/Asp.NetCore/SqlServerTest/src/MySqlTest/Demos/1_Query.cs

@ -211,7 +211,7 @@ namespace OrmTest.Demo
.Where((st, sc) => st.Id == 1 && sc.Id == 2).ToList();
//SELECT [st].[Id],[st].[SchoolId],[st].[Name],[st].[CreateTime] FROM [Student] st
//Left JOIN School sc ON ( [st].[SchoolId] = [sc].[Id] )
//Left JOIN `School` sc ON ( [st].[SchoolId] = [sc].[Id] )
//WHERE ( [sc].[Id] = @Id0 ) AND ( [st].[Id] = @Id1 ) AND (( [st].[Id] = @Id2 ) AND ( [sc].[Id] = @Id3 ))
@ -337,7 +337,7 @@ namespace OrmTest.Demo
.Where("st.id>@id")
.AddParameters(new { id = 1 })
.Select("st.*").ToList();
//SELECT st.* FROM [Student] st Left JOIN School sh ON sh.id=st.schoolid WHERE st.id>@id
//SELECT st.* FROM [Student] st Left JOIN `School` sh ON sh.id=st.schoolid WHERE st.id>@id
}
private static void Enum()
{

10
Src/Asp.NetCore/SqlServerTest/src/MySqlTest/Demos/3_Insert.cs

@ -21,20 +21,20 @@ namespace OrmTest.Demo
var t2 = db.Insertable(insertObj).ExecuteCommand();
//Insert reutrn Identity Value
var t3 = db.Insertable(insertObj).ExecuteReutrnIdentity();
var t3 = db.Insertable(insertObj).ExecuteReturnIdentity();
//Only insert Name and SchoolId
var t4 = db.Insertable(insertObj).InsertColumns(it => new { it.Name, it.SchoolId }).ExecuteReutrnIdentity();
var t4_1 = db.Insertable(insertObj).InsertColumns(it => it=="Name"||it== "SchoolId").ExecuteReutrnIdentity();
var t4 = db.Insertable(insertObj).InsertColumns(it => new { it.Name, it.SchoolId }).ExecuteReturnIdentity();
var t4_1 = db.Insertable(insertObj).InsertColumns(it => it=="Name"||it== "SchoolId").ExecuteReturnIdentity();
//Ignore TestId
var t5 = db.Insertable(insertObj).IgnoreColumns(it => new { it.Name, it.TestId }).ExecuteReutrnIdentity();
var t5 = db.Insertable(insertObj).IgnoreColumns(it => new { it.Name, it.TestId }).ExecuteReturnIdentity();
//Ignore TestId
var t6 = db.Insertable(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").ExecuteReutrnIdentity();
var t6 = db.Insertable(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").ExecuteReturnIdentity();
//Use Lock

2
Src/Asp.NetCore/SqlServerTest/src/MySqlTest/Demos/7_Filter.cs

@ -22,7 +22,7 @@ namespace OrmTest.Demo
var sql2 = db.Queryable<Student, School>((f, s) => new object[] { JoinType.Left, f.SchoolId == s.Id }).ToSql();
//SELECT[f].[ID],[f].[SchoolId],[f].[Name],[f].[CreateTime]
//FROM[STudent] f Left JOIN School s ON([f].[SchoolId] = [s].[Id]) WHERE f.isDelete=0
//FROM[STudent] f Left JOIN `School` s ON([f].[SchoolId] = [s].[Id]) WHERE f.isDelete=0
//Specify name filter

2
Src/Asp.NetCore/SqlServerTest/src/MySqlTest/UnitTest/DataTest.cs

@ -39,7 +39,7 @@ namespace OrmTest.UnitTest
Varbinary2 = null,
String = "string"
};
var id = db.Insertable<DataTestInfo>(insertObject).ExecuteReutrnIdentity();
var id = db.Insertable<DataTestInfo>(insertObject).ExecuteReturnIdentity();
var data = db.Queryable<DataTestInfo>().InSingle(id);
if (
insertObject.Datetime1.ToString("yyyy-MM-dd") != data.Datetime1.ToString("yyyy-MM-dd") ||

2
Src/Asp.NetCore/SqlServerTest/src/MySqlTest/UnitTest/Mapping .cs

@ -32,7 +32,7 @@ namespace OrmTest.UnitTest
.GroupBy(st => st.Id)
.GroupBy((st,sc) => sc.Id).OrderBy(st => st.Id,OrderByType.Asc)
.Select((st,sc)=> new { stid=st.Id,scid=sc.Id}).ToSql();
base.Check(@"SELECT `st`.`ID` AS `stid` , `sc`.`id` AS `scid` FROM `STudent` st Left JOIN School sc ON ( `st`.`SchoolId` = `sc`.`id` ) WHERE ( `st`.`ID` = @Id0 ) AND ( `sc`.`id` = @Id1 ) AND ( `sc`.`id` = `st`.`ID` )GROUP BY `st`.`ID`,`sc`.`id` ORDER BY `st`.`ID` ASC ",
base.Check(@"SELECT `st`.`ID` AS `stid` , `sc`.`id` AS `scid` FROM `STudent` st Left JOIN `School` sc ON ( `st`.`SchoolId` = `sc`.`id` ) WHERE ( `st`.`ID` = @Id0 ) AND ( `sc`.`id` = @Id1 ) AND ( `sc`.`id` = `st`.`ID` )GROUP BY `st`.`ID`,`sc`.`id` ORDER BY `st`.`ID` ASC ",
null, t2.Key, null, " Mapping t2 error");
var x2 = GetInstance();
}

6
Src/Asp.NetCore/SqlServerTest/src/MySqlTest/UnitTest/Query/JoinQuery.cs

@ -36,7 +36,7 @@ namespace OrmTest.UnitTest
.Where("st.id>@id")
.AddParameters(new { id = 1 })
.Select("st.*").ToSql();
string sql = @"SELECT st.* FROM `Student` st Left JOIN School sh ON sh.id=st.schoolid WHERE st.id>@id ";
string sql = @"SELECT st.* FROM `Student` st Left JOIN `School` sh ON sh.id=st.schoolid WHERE st.id>@id ";
base.Check(sql,new List<SugarParameter>() {new SugarParameter("@id",1)}, join3.Key, join3.Value, "join 3 Error");
}
}
@ -48,7 +48,7 @@ namespace OrmTest.UnitTest
var join1 = db.Queryable<Student, School>((st, sc) => new object[] {
JoinType.Left,st.SchoolId==sc.Id
}).Where(st => st.Id > 0).Select<Student>("*").ToSql();
base.Check(@"SELECT * FROM `STudent` st Left JOIN School sc ON ( `st`.`SchoolId` = `sc`.`Id` ) WHERE ( `st`.`ID` > @Id0 ) ",
base.Check(@"SELECT * FROM `STudent` st Left JOIN `School` sc ON ( `st`.`SchoolId` = `sc`.`Id` ) WHERE ( `st`.`ID` > @Id0 ) ",
new List<SugarParameter>() {
new SugarParameter("@Id0",0)
}, join1.Key, join1.Value, "join 1 Error");
@ -61,7 +61,7 @@ namespace OrmTest.UnitTest
var join2 = db.Queryable<Student, School>((st, sc) => new object[] {
JoinType.Left,st.SchoolId==sc.Id
}).Where(st => st.Id > 2).Select<Student>("*").ToSql();
base.Check(@"SELECT * FROM `STudent` st Left JOIN School sc ON ( `st`.`SchoolId` = `sc`.`Id` ) WHERE ( `st`.`ID` > @Id0 ) ",
base.Check(@"SELECT * FROM `STudent` st Left JOIN `School` sc ON ( `st`.`SchoolId` = `sc`.`Id` ) WHERE ( `st`.`ID` > @Id0 ) ",
new List<SugarParameter>() {
new SugarParameter("@Id0",2)
}, join2.Key, join2.Value, "join 2 Error");

6
Src/Asp.NetCore/SqlServerTest/src/MySqlTest/UnitTest/Query/SelectQuery.cs

@ -50,7 +50,7 @@ namespace OrmTest.UnitTest
var t1 = db.Queryable<Student, School>((st, sc) => new object[] {
JoinType.Inner,st.Id==sc.Id
}).GroupBy(st => st.Id).Having(st => SqlFunc.AggregateAvg(st.Id) == 1).Select(st => new { avgId = SqlFunc.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 ) ",
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)
}
@ -64,7 +64,7 @@ namespace OrmTest.UnitTest
.Where(st => st.Id > 0)
.Select((st, st2) => new { stid = st.Id, scId = st2.Id, xx = st }).ToSql();
base.Check("SELECT `st`.`Id` AS `stid` , `st2`.`Id` AS `scId` , `st`.`Id` AS `School.Id` , `st`.`Name` AS `School.Name` FROM `School` st Left JOIN School st2 ON ( `st`.`Id` = `st2`.`Id` ) WHERE ( `st`.`Id` > @Id0 ) "
base.Check("SELECT `st`.`Id` AS `stid` , `st2`.`Id` AS `scId` , `st`.`Id` AS `School.Id` , `st`.`Name` AS `School.Name` FROM `School` st Left JOIN `School` st2 ON ( `st`.`Id` = `st2`.`Id` ) WHERE ( `st`.`Id` > @Id0 ) "
, new List<SugarParameter>() {
new SugarParameter("@Id0",0)
}, t2.Key, t2.Value, "select t2 Error");
@ -75,7 +75,7 @@ namespace OrmTest.UnitTest
JoinType.Left,sc2.Id==sc.Id
}).Where(st => st.Id > 0)
.Select<School>((st) => new School() { Id = st.Id }).ToSql();
base.Check("SELECT `st`.`ID` AS `Id` FROM `STudent` st Left JOIN School sc ON ( `st`.`SchoolId` = `sc`.`Id` ) Left JOIN School sc2 ON ( `sc2`.`Id` = `sc`.`Id` ) WHERE ( `st`.`ID` > @Id0 ) ",
base.Check("SELECT `st`.`ID` AS `Id` FROM `STudent` st Left JOIN `School` sc ON ( `st`.`SchoolId` = `sc`.`Id` ) Left JOIN `School` sc2 ON ( `sc2`.`Id` = `sc`.`Id` ) WHERE ( `st`.`ID` > @Id0 ) ",
new List<SugarParameter>() {
new SugarParameter("@Id0",0)
}, t3.Key, t3.Value, "select t3 Error");

Loading…
Cancel
Save