|
|
@ -16,7 +16,7 @@ namespace OrmTest |
|
|
|
SqlSugarClient();//Create db
|
|
|
|
DbContext();//Optimizing SqlSugarClient usage
|
|
|
|
SingletonPattern();//Singleten Pattern
|
|
|
|
//DistributedTransactionExample(); The demo requires three different databases
|
|
|
|
DistributedTransactionExample(); |
|
|
|
MasterSlave();//Read-write separation
|
|
|
|
CustomAttribute(); |
|
|
|
} |
|
|
@ -229,7 +229,7 @@ namespace OrmTest |
|
|
|
new ConnectionConfig(){ ConfigId="1", DbType=DbType.SqlServer, ConnectionString=Config.ConnectionString,InitKeyType=InitKeyType.Attribute,IsAutoCloseConnection=true }, |
|
|
|
new ConnectionConfig(){ ConfigId="2", DbType=DbType.SqlServer, ConnectionString=Config.ConnectionString2 ,InitKeyType=InitKeyType.Attribute ,IsAutoCloseConnection=true} |
|
|
|
}); |
|
|
|
|
|
|
|
var db1 = db.Ado.Connection.Database; |
|
|
|
//use db1
|
|
|
|
db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Order), typeof(OrderItem));//
|
|
|
|
db.Insertable(new Order() { Name = "order1", CreateTime = DateTime.Now }).ExecuteCommand(); |
|
|
@ -237,11 +237,16 @@ namespace OrmTest |
|
|
|
|
|
|
|
//use db2
|
|
|
|
db.ChangeDatabase("2"); |
|
|
|
var db2 = db.Ado.Connection.Database; |
|
|
|
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<Order>().Count()); |
|
|
|
|
|
|
|
if (db2 == db1) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
// Example 1
|
|
|
|
Console.WriteLine("Example 1"); |
|
|
|
try |
|
|
|