diff --git a/Src/Asp.Net/SqlServerTest/Config.cs b/Src/Asp.Net/SqlServerTest/Config.cs index e13992dcb..8a5e3975f 100644 --- a/Src/Asp.Net/SqlServerTest/Config.cs +++ b/Src/Asp.Net/SqlServerTest/Config.cs @@ -9,8 +9,7 @@ namespace OrmTest public class Config { public static string ConnectionString = "server=.;uid=sa;pwd=haosql;database=SQLSUGAR4XTEST"; - public static string ConnectionString2 = "server=.;uid=sa;pwd=haosql;database=sqlsugar4xtest"; - public static string ConnectionString3 = "server=.;uid=sa;pwd=haosql;database=sqlsugar4xtesT"; - public static string ConnectionString4 = "server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=haosql"; + public static string ConnectionString2 = "server=.;uid=sa;pwd=haosql;database=SQLSUGAR4XTEST2"; + public static string ConnectionString3 = "server=.;uid=sa;pwd=haosql;database=SQLSUGAR4XTEST3"; } } diff --git a/Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs b/Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs index b3a670ee5..89b2aeb45 100644 --- a/Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs +++ b/Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs @@ -198,41 +198,33 @@ namespace OrmTest SqlSugarClient db = new SqlSugarClient(new List() { new ConnectionConfig(){ ConfigId=1, DbType=DbType.SqlServer, ConnectionString=Config.ConnectionString,InitKeyType=InitKeyType.Attribute,IsAutoCloseConnection=true }, - new ConnectionConfig(){ ConfigId=2, DbType=DbType.MySql, ConnectionString=Config.ConnectionString4 ,InitKeyType=InitKeyType.Attribute ,IsAutoCloseConnection=true} + new ConnectionConfig(){ ConfigId=2, DbType=DbType.SqlServer, ConnectionString=Config.ConnectionString2 ,InitKeyType=InitKeyType.Attribute ,IsAutoCloseConnection=true} }); - db.MappingTables.Add(typeof(Order).Name, typeof(Order).Name + "2018"); - db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Order)); - - db.MappingTables.Add(typeof(Order).Name, typeof(Order).Name + "2019"); - db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Order));// - - //use first(SqlServer) + //use db1 db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Order), typeof(OrderItem));// db.Insertable(new Order() { Name = "order1", CreateTime = DateTime.Now }).ExecuteCommand(); Console.WriteLine(db.CurrentConnectionConfig.DbType + ":" + db.Queryable().Count()); - //use mysql - db.ChangeDatabase(it => it.DbType == DbType.MySql); + //use db2 + db.ChangeDatabase("2"); + db.DbMaintenance.CreateDatabase();//Create Database2 db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Order), typeof(OrderItem)); db.Insertable(new Order() { Name = "order1", CreateTime = DateTime.Now }).ExecuteCommand(); Console.WriteLine(db.CurrentConnectionConfig.DbType + ":" + db.Queryable().Count()); - //SqlServer - db.ChangeDatabase(it => it.DbType == DbType.SqlServer);//use sqlserver - // Example 1 Console.WriteLine("Example 1"); try { db.BeginTran(); - db.ChangeDatabase(it => it.DbType == DbType.SqlServer);//use sqlserver + db.ChangeDatabase("1");//use db1 db.Deleteable().ExecuteCommand(); Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType); Console.WriteLine(db.Queryable().Count()); - db.ChangeDatabase(it => it.DbType == DbType.MySql);//use mysql + db.ChangeDatabase("2");//use db2 db.Deleteable().ExecuteCommand(); Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType); Console.WriteLine(db.Queryable().Count()); @@ -244,11 +236,11 @@ namespace OrmTest { db.RollbackTran(); Console.WriteLine("---Roll back"); - db.ChangeDatabase(it => it.DbType == DbType.SqlServer);//use sqlserver + db.ChangeDatabase("1");//use db1 Console.WriteLine(db.CurrentConnectionConfig.DbType); Console.WriteLine(db.Queryable().Count()); - db.ChangeDatabase(it => it.DbType == DbType.MySql);//use mysql + db.ChangeDatabase("2");//use db2 Console.WriteLine(db.CurrentConnectionConfig.DbType); Console.WriteLine(db.Queryable().Count()); } @@ -261,12 +253,12 @@ namespace OrmTest var result=db.UseTran(() => { - db.ChangeDatabase(it => it.DbType == DbType.SqlServer);//use sqlserver + db.ChangeDatabase("1");//use db1 db.Deleteable().ExecuteCommand(); Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType); Console.WriteLine(db.Queryable().Count()); - db.ChangeDatabase(it => it.DbType == DbType.MySql);//use mysql + db.ChangeDatabase("2");//use db2 db.Deleteable().ExecuteCommand(); Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType); Console.WriteLine(db.Queryable().Count()); @@ -275,11 +267,11 @@ namespace OrmTest }); if (result.IsSuccess == false) { Console.WriteLine("---Roll back"); - db.ChangeDatabase(it => it.DbType == DbType.SqlServer);//use sqlserver + db.ChangeDatabase("1");//use db1 Console.WriteLine(db.CurrentConnectionConfig.DbType); Console.WriteLine(db.Queryable().Count()); - db.ChangeDatabase(it => it.DbType == DbType.MySql);//use mysql + db.ChangeDatabase("2");//use db2 Console.WriteLine(db.CurrentConnectionConfig.DbType); Console.WriteLine(db.Queryable().Count()); } @@ -290,12 +282,12 @@ namespace OrmTest var result2 = db.UseTranAsync(() => { - db.ChangeDatabase(it => it.DbType == DbType.SqlServer);//use sqlserver + db.ChangeDatabase("1");//use db1 db.Deleteable().ExecuteCommand(); Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType); Console.WriteLine(db.Queryable().Count()); - db.ChangeDatabase(it => it.DbType == DbType.MySql);//use mysql + db.ChangeDatabase("2");//use db2 db.Deleteable().ExecuteCommand(); Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType); Console.WriteLine(db.Queryable().Count());