Skip to content

Commit

Permalink
Refactor - factor out common sql execution code
Browse files Browse the repository at this point in the history
Preparing to squash db interface to single method
  • Loading branch information
timabell committed Feb 21, 2015
1 parent ec8db54 commit b0163a3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions EfEnumToLookup/LookupGenerator/EnumToLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,20 @@ public void Apply(DbContext context)
Values = GetLookupValues(enm),
}).ToList();

sqlServerHandler.CreateTables(lookups, (sql) => context.Database.ExecuteSqlCommand(sql));
sqlServerHandler.PopulateLookups(lookups, (sql, parameters) => context.Database.ExecuteSqlCommand(sql, parameters.Cast<object>().ToArray()));
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) => context.Database.ExecuteSqlCommand(sql));
sqlServerHandler.AddForeignKeys(enumReferences, (sql) => ExecuteSqlCommand(context, sql));
}

private static int ExecuteSqlCommand(DbContext context, string sql, IEnumerable<SqlParameter> parameters = null)
{
if (parameters == null)
{
return context.Database.ExecuteSqlCommand(sql);
}
return context.Database.ExecuteSqlCommand(sql, parameters.Cast<object>().ToArray());
}

private string EnumName(object value, Type lookup)
Expand Down

0 comments on commit b0163a3

Please sign in to comment.