Browse Source

Update DbMaintenance

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
278f35d466
  1. 7
      Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs
  2. 8
      Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs
  3. 2
      Src/Asp.Net/SqlSugar/Realization/MySql/CodeFirst/MySqlCodeFirst.cs
  4. 5
      Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs
  5. 15
      Src/Asp.Net/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs
  6. 2
      Src/Asp.Net/SqlSugar/Realization/Sqlite/CodeFirst/SqliteCodeFirst.cs

7
Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs

@ -87,12 +87,7 @@ namespace SqlSugar
columns.Add(dbColumnInfo);
}
}
this.Context.DbMaintenance.CreateTable(tableName, columns);
var pkColumns = entityInfo.Columns.Where(it => it.IsPrimarykey).ToList();
foreach (var item in pkColumns)
{
this.Context.DbMaintenance.AddPrimaryKey(tableName, item.DbColumnName);
}
this.Context.DbMaintenance.CreateTable(tableName, columns,true);
}
public virtual void ExistLogic(EntityInfo entityInfo)
{

8
Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs

@ -141,13 +141,7 @@ namespace SqlSugar
this.Context.Ado.ExecuteCommand(sql);
return true;
}
public virtual bool CreateTable(string tableName, List<DbColumnInfo> columns, bool isCreatePrimaryKey = true)
{
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
string sql = GetCreateTableSql(tableName, columns);
this.Context.Ado.ExecuteCommand(sql);
return true;
}
public abstract bool CreateTable(string tableName, List<DbColumnInfo> columns, bool isCreatePrimaryKey = true);
public virtual bool DropTable(string tableName)
{
tableName = this.SqlBuilder.GetTranslationTableName(tableName);

2
Src/Asp.Net/SqlSugar/Realization/MySql/CodeFirst/MySqlCodeFirst.cs

@ -20,7 +20,7 @@ namespace SqlSugar
columns.Add(dbColumnInfo);
}
}
this.Context.DbMaintenance.CreateTable(tableName, columns);
this.Context.DbMaintenance.CreateTable(tableName, columns,true);
}
protected override DbColumnInfo EntityColumnToDbColumn(EntityInfo entityInfo, string tableName, EntityColumnInfo item)
{

5
Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs

@ -259,6 +259,11 @@ namespace SqlSugar
return comments.HasValue() ? comments.First(it=>it.DbColumnName.Equals(filedName,StringComparison.CurrentCultureIgnoreCase)).ColumnDescription : "";
}
public override bool CreateTable(string tableName, List<DbColumnInfo> columns, bool isCreatePrimaryKey = true)
{
throw new NotImplementedException();
}
#endregion
}
}

15
Src/Asp.Net/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs

@ -201,5 +201,20 @@ namespace SqlSugar
}
}
#endregion
public override bool CreateTable(string tableName, List<DbColumnInfo> columns, bool isCreatePrimaryKey = true)
{
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
string sql = GetCreateTableSql(tableName, columns);
this.Context.Ado.ExecuteCommand(sql);
if (isCreatePrimaryKey) {
var pkColumns = columns.Where(it => it.IsPrimarykey).ToList();
foreach (var item in pkColumns)
{
this.Context.DbMaintenance.AddPrimaryKey(tableName, item.DbColumnName);
}
}
return true;
}
}
}

2
Src/Asp.Net/SqlSugar/Realization/Sqlite/CodeFirst/SqliteCodeFirst.cs

@ -39,7 +39,7 @@ namespace SqlSugar
columns.Add(dbColumnInfo);
}
}
this.Context.DbMaintenance.CreateTable(tableName, columns);
this.Context.DbMaintenance.CreateTable(tableName, columns,true);
}
protected override DbColumnInfo EntityColumnToDbColumn(EntityInfo entityInfo, string tableName, EntityColumnInfo item)
{

Loading…
Cancel
Save