mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Update demo& Add CreateIndex(+4)
This commit is contained in:
parent
9622f3110d
commit
8a76bf0f73
@ -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
|
||||
|
@ -325,6 +325,12 @@ namespace SqlSugar
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
public virtual bool CreateIndex(string tableName, string[] columnNames, string IndexName, bool isUnique = false)
|
||||
{
|
||||
string sql = string.Format("CREATE {3} INDEX {2} ON {0}({1})", tableName, string.Join(",", columnNames), IndexName, isUnique ? "UNIQUE" : "");
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
public virtual bool IsAnyIndex(string indexName)
|
||||
{
|
||||
string sql = string.Format(this.IsAnyIndexSql, indexName);
|
||||
|
@ -29,6 +29,7 @@ namespace SqlSugar
|
||||
#region DDL
|
||||
bool AddDefaultValue(string tableName,string columnName,string defaultValue);
|
||||
bool CreateIndex(string tableName, string [] columnNames, bool isUnique=false);
|
||||
bool CreateIndex(string tableName, string[] columnNames, string IndexName, bool isUnique = false);
|
||||
bool DropTable(string tableName);
|
||||
bool TruncateTable(string tableName);
|
||||
bool TruncateTable<T>();
|
||||
|
Loading…
Reference in New Issue
Block a user