mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Update MySql
This commit is contained in:
parent
20ec1bc3c4
commit
9fc7cbb041
@ -28,7 +28,7 @@ namespace OrmTest
|
||||
new Insert(1).Init();
|
||||
new Delete(1).Init();
|
||||
new Update(1).Init();
|
||||
// new Mapping(1).Init();
|
||||
new Mapping(1).Init();
|
||||
// new DataTest(1).Init();
|
||||
|
||||
// /***Performance Test***/
|
||||
|
@ -20,7 +20,7 @@ namespace OrmTest.UnitTest
|
||||
|
||||
var db = GetInstance();
|
||||
var t1= db.Queryable<Student>().Where(it=>it.Id==1).ToSql();
|
||||
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WHERE ( [ID] = @Id0 ) ", null, t1.Key, null,"Mapping t1 error");
|
||||
base.Check("SELECT `ID`,`SchoolId`,`Name`,`CreateTime` FROM `STudent` WHERE ( `ID` = @Id0 ) ", null, t1.Key, null,"Mapping t1 error");
|
||||
|
||||
db.MappingColumns.Add("Id", "id", "School");
|
||||
var t2 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||
@ -32,14 +32,14 @@ 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();
|
||||
}
|
||||
|
||||
public SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() {InitKeyType=InitKeyType.Attribute, ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() {InitKeyType=InitKeyType.Attribute, ConnectionString = Config.ConnectionString, DbType = DbType.MySql, IsAutoCloseConnection = true });
|
||||
return db;
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ namespace OrmTest.UnitTest
|
||||
//db.MappingColumns.Add("id","dbid", "Student");
|
||||
|
||||
var t1 = db.Updateable(updateObj).ToSql();
|
||||
base.Check(@"UPDATE [STudent] SET
|
||||
[SchoolId]=@SchoolId,[Name]=@Name,[CreateTime]=@CreateTime WHERE [Id]=@Id", new List<SugarParameter>() {
|
||||
base.Check(@"UPDATE `STudent` SET
|
||||
`SchoolId`=@SchoolId,`Name`=@Name,`CreateTime`=@CreateTime WHERE `ID`=@ID", new List<SugarParameter>() {
|
||||
new SugarParameter("@SchoolId",0),
|
||||
new SugarParameter("@ID",1),
|
||||
new SugarParameter("@CreateTime", Convert.ToDateTime("2017-05-21 09:56:12.610")),
|
||||
@ -39,16 +39,16 @@ namespace OrmTest.UnitTest
|
||||
db.IgnoreColumns = null;
|
||||
//Only update Name
|
||||
var t3 = db.Updateable(updateObj).UpdateColumns(it => new { it.Name }).ToSql();
|
||||
base.Check(@"UPDATE [STudent] SET
|
||||
[Name]=@Name WHERE [Id]=@Id", new List<SugarParameter>() {
|
||||
base.Check(@"UPDATE `STudent` SET
|
||||
`Name`=@Name WHERE `ID`=@ID", new List<SugarParameter>() {
|
||||
new SugarParameter("@ID",1),
|
||||
new SugarParameter("@Name", "jack")
|
||||
}, t3.Key, t3.Value, "Update t3 error");
|
||||
|
||||
//Ignore Name and TestId
|
||||
var t4 = db.Updateable(updateObj).IgnoreColumns(it => new { it.Name, it.TestId }).ToSql();
|
||||
base.Check(@"UPDATE [STudent] SET
|
||||
[SchoolId]=@SchoolId,[CreateTime]=@CreateTime WHERE [Id]=@Id", new List<SugarParameter>() {
|
||||
base.Check(@"UPDATE `STudent` SET
|
||||
`SchoolId`=@SchoolId,`CreateTime`=@CreateTime WHERE `ID`=@ID", new List<SugarParameter>() {
|
||||
new SugarParameter("@CreateTime",Convert.ToDateTime("2017-05-21 09:56:12.610")),
|
||||
new SugarParameter("@SchoolId", 0),
|
||||
new SugarParameter("@ID",1),
|
||||
@ -56,8 +56,8 @@ namespace OrmTest.UnitTest
|
||||
|
||||
//Ignore Name and TestId
|
||||
var t5 = db.Updateable(updateObj).IgnoreColumns(it => it == "Name" || it == "TestId").With(SqlWith.UpdLock).ToSql();
|
||||
base.Check(@"UPDATE [STudent] WITH(UPDLOCK) SET
|
||||
[SchoolId]=@SchoolId,[CreateTime]=@CreateTime WHERE [Id]=@Id", new List<SugarParameter>() {
|
||||
base.Check(@"UPDATE `STudent` SET
|
||||
`SchoolId`=@SchoolId,`CreateTime`=@CreateTime WHERE `ID`=@ID", new List<SugarParameter>() {
|
||||
new SugarParameter("@CreateTime",Convert.ToDateTime("2017-05-21 09:56:12.610")),
|
||||
new SugarParameter("@SchoolId", 0),
|
||||
new SugarParameter("@ID",1),
|
||||
@ -66,8 +66,8 @@ namespace OrmTest.UnitTest
|
||||
|
||||
//Use Lock
|
||||
var t6 = db.Updateable(updateObj).With(SqlWith.UpdLock).ToSql();
|
||||
base.Check(@"UPDATE [STudent] WITH(UPDLOCK) SET
|
||||
[SchoolId]=@SchoolId,[Name]=@Name,[CreateTime]=@CreateTime WHERE [Id]=@Id", new List<SugarParameter>() {
|
||||
base.Check(@"UPDATE `STudent` SET
|
||||
`SchoolId`=@SchoolId,`Name`=@Name,`CreateTime`=@CreateTime WHERE `ID`=@ID", new List<SugarParameter>() {
|
||||
new SugarParameter("@SchoolId",0),
|
||||
new SugarParameter("@ID",1),
|
||||
new SugarParameter("@CreateTime", Convert.ToDateTime("2017-05-21 09:56:12.610")),
|
||||
@ -77,21 +77,21 @@ namespace OrmTest.UnitTest
|
||||
|
||||
// //update List<T>
|
||||
// var t7 = db.Updateable(updateObjs).With(SqlWith.UpdLock).ToSql();
|
||||
// base.Check(@"UPDATE S SET S.[SchoolId]=T.[SchoolId],S.[Name]=T.[Name],S.[CreateTime]=T.[CreateTime] FROM [STudent] S WITH(UPDLOCK) INNER JOIN (
|
||||
// base.Check(@"UPDATE S SET S.`SchoolId`=T.`SchoolId`,S.`Name`=T.`Name`,S.`CreateTime`=T.`CreateTime` FROM `STudent` S WITH(UPDLOCK) INNER JOIN (
|
||||
|
||||
// SELECT N'1' AS ID,N'0' AS SchoolId,N'jack' AS Name,'2017-05-21 09:56:12.610' AS CreateTime
|
||||
//UNION ALL
|
||||
// SELECT N'2' AS ID,N'0' AS SchoolId,N'sun' AS Name,NULL AS CreateTime
|
||||
|
||||
|
||||
// ) T ON S.[Id]=T.[Id]
|
||||
// ) T ON S.`Id`=T.`Id`
|
||||
// ; ", null, t7.Key, null,"Update t7 error");
|
||||
|
||||
//Re Set Value
|
||||
var t8 = db.Updateable(updateObj)
|
||||
.ReSetValue(it=>it.Name==(it.Name+1)).ToSql();
|
||||
base.Check(@"UPDATE [STudent] SET
|
||||
[SchoolId]=@SchoolId, [Name] =( [Name] + @Const0 ),[CreateTime]=@CreateTime WHERE [Id]=@Id",
|
||||
base.Check(@"UPDATE `STudent` SET
|
||||
`SchoolId`=@SchoolId, `Name` =( `Name` + @Const0 ),`CreateTime`=@CreateTime WHERE `ID`=@ID",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@SchoolId",0),
|
||||
new SugarParameter("@ID",1),
|
||||
@ -103,8 +103,8 @@ namespace OrmTest.UnitTest
|
||||
//Where By Expression
|
||||
var t9 = db.Updateable(updateObj)
|
||||
.Where(it => it.Id==1).ToSql();
|
||||
base.Check(@"UPDATE [STudent] SET
|
||||
[SchoolId]=@SchoolId,[Name]=@Name,[CreateTime]=@CreateTime WHERE ( [ID] = @Id0 )",
|
||||
base.Check(@"UPDATE `STudent` SET
|
||||
`SchoolId`=@SchoolId,`Name`=@Name,`CreateTime`=@CreateTime WHERE ( `ID` = @Id0 )",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@SchoolId",0),
|
||||
new SugarParameter("@ID",1),
|
||||
@ -115,8 +115,8 @@ namespace OrmTest.UnitTest
|
||||
updateObj.SchoolId = 18;
|
||||
string name = "x";
|
||||
var t10 = db.Updateable<Student>().UpdateColumns(it => new Student() { Name =name, SchoolId=updateObj.SchoolId }).Where(it=>it.Id==11).ToSql();
|
||||
base.Check(@"UPDATE [STudent] SET
|
||||
[SchoolId] = @Const0 , [Name] = @const3 WHERE ( [ID] = @Id1 )", new List<SugarParameter>() {
|
||||
base.Check(@"UPDATE `STudent` SET
|
||||
`SchoolId` = @Const0 , `Name` = @const3 WHERE ( `ID` = @Id1 )", new List<SugarParameter>() {
|
||||
new SugarParameter("@const3","x"),
|
||||
new SugarParameter("@Const0",18),
|
||||
new SugarParameter("@Id1",11)},
|
||||
@ -128,7 +128,7 @@ namespace OrmTest.UnitTest
|
||||
|
||||
public SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.MySql, IsAutoCloseConnection = true });
|
||||
return db;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user