diff --git a/EfEnumToLookup/LookupGenerator/EnumToLookup.cs b/EfEnumToLookup/LookupGenerator/EnumToLookup.cs index 88d7bb0..9a03538 100644 --- a/EfEnumToLookup/LookupGenerator/EnumToLookup.cs +++ b/EfEnumToLookup/LookupGenerator/EnumToLookup.cs @@ -93,11 +93,7 @@ public void Apply(DbContext context) Values = GetLookupValues(enm), }).ToList(); - sqlServerHandler.CreateTables(lookups, (sql) => ExecuteSqlCommand(context, sql)); - sqlServerHandler.PopulateLookups(lookups, (sql, parameters) => ExecuteSqlCommand(context, sql, parameters)); - - // add fks from all referencing tables - sqlServerHandler.AddForeignKeys(enumReferences, (sql) => ExecuteSqlCommand(context, sql)); + sqlServerHandler.Apply(lookups, enumReferences, (sql, parameters) => ExecuteSqlCommand(context, sql, parameters)); } private static int ExecuteSqlCommand(DbContext context, string sql, IEnumerable parameters = null) diff --git a/EfEnumToLookup/LookupGenerator/SqlServerHandler.cs b/EfEnumToLookup/LookupGenerator/SqlServerHandler.cs index a8243df..a69f569 100644 --- a/EfEnumToLookup/LookupGenerator/SqlServerHandler.cs +++ b/EfEnumToLookup/LookupGenerator/SqlServerHandler.cs @@ -27,7 +27,15 @@ class SqlServerHandler /// public string TableNameSuffix { get; set; } - internal void CreateTables(IEnumerable enums, Action runSql) + + internal void Apply(List lookups, IList enumReferences, Action> runSql) + { + CreateTables(lookups, (sql) => runSql(sql, null)); + PopulateLookups(lookups, runSql); + AddForeignKeys(enumReferences, (sql) => runSql(sql, null)); + } + + private void CreateTables(IEnumerable enums, Action runSql) { foreach (var lookup in enums) { @@ -37,7 +45,7 @@ internal void CreateTables(IEnumerable enums, Action runSql) } } - internal void AddForeignKeys(IEnumerable refs, Action runSql) + private void AddForeignKeys(IEnumerable refs, Action runSql) { foreach (var enumReference in refs) { @@ -52,7 +60,7 @@ internal void AddForeignKeys(IEnumerable refs, Action run } } - internal void PopulateLookups(IEnumerable lookupData, Action> runSql) + private void PopulateLookups(IEnumerable lookupData, Action> runSql) { foreach (var lookup in lookupData) {