|
|
@@ -189,7 +189,7 @@ public static class SqlSugarSetup
|
|
|
{
|
|
|
if (!config.EnableInitDb) return;
|
|
|
|
|
|
- var dbProvider = db.GetConnectionScope(config.ConfigId);
|
|
|
+ SqlSugarScopeProvider dbProvider = db.GetConnectionScope(config.ConfigId);
|
|
|
|
|
|
// 创建数据库
|
|
|
if (config.DbType != SqlSugar.DbType.Oracle)
|
|
|
@@ -229,25 +229,10 @@ public static class SqlSugarSetup
|
|
|
if (tAtt != null && tAtt.configId.ToString() != config.ConfigId) continue;
|
|
|
if (tAtt == null && config.ConfigId != SqlSugarConst.ConfigId) continue;
|
|
|
|
|
|
- var seedDataTable = seedData.ToList().ToDataTable();
|
|
|
- seedDataTable.TableName = dbProvider.EntityMaintenance.GetEntityInfo(entityType).DbTableName;
|
|
|
- if (config.EnableUnderLine) // 驼峰转下划线
|
|
|
- {
|
|
|
- foreach (DataColumn col in seedDataTable.Columns)
|
|
|
- col.ColumnName = UtilMethods.ToUnderLine(col.ColumnName);
|
|
|
- }
|
|
|
- if (seedDataTable.Columns.Contains(SqlSugarConst.PrimaryKey))
|
|
|
- {
|
|
|
- var storage = dbProvider.CopyNew().Storageable(seedDataTable).WhereColumns(SqlSugarConst.PrimaryKey).ToStorage();
|
|
|
- storage.AsInsertable.ExecuteCommand();
|
|
|
- var ignoreUpdate = hasDataMethod.GetCustomAttribute<IgnoreUpdateAttribute>();
|
|
|
- if (ignoreUpdate == null) storage.AsUpdateable.ExecuteCommand();
|
|
|
- }
|
|
|
- else // 没有主键或者不是预定义的主键(有重复的可能)
|
|
|
- {
|
|
|
- var storage = dbProvider.CopyNew().Storageable(seedDataTable).ToStorage();
|
|
|
- storage.AsInsertable.ExecuteCommand();
|
|
|
- }
|
|
|
+ var storage = dbProvider.CopyNew().StorageableByObject(seedData.ToList()).ToStorage();
|
|
|
+ storage.AsInsertable.ExecuteCommand();
|
|
|
+ var ignoreUpdate = hasDataMethod.GetCustomAttribute<IgnoreUpdateAttribute>();
|
|
|
+ if (ignoreUpdate == null) storage.AsUpdateable.ExecuteCommand();
|
|
|
}
|
|
|
}
|
|
|
|