private IEntityType GetEntityType <TEntity>() where TEntity : class { var options = new DbContextOptionsBuilder <NecroDancerContext>() .UseSqlServer(connection) .Options; using (var db = new NecroDancerContext(options)) { return(db.Model.GetEntityTypes().FirstOrDefault(t => t.ClrType == typeof(TEntity))); } }
/// <summary> /// /// </summary> /// <param name="context"></param> public static void EnsureSeedData(this NecroDancerContext context) { if (!context.Database.GetPendingMigrations().Any()) { if (!context.Products.Any()) { var products = JsonConvert.DeserializeObject <IEnumerable <Product> >(Resources.Products); context.Products.AddRange(products); context.SaveChanges(); } if (!context.Modes.Any()) { var modes = JsonConvert.DeserializeObject <IEnumerable <Mode> >(Resources.Modes); context.Modes.AddRange(modes); context.SaveChanges(); } if (!context.Runs.Any()) { var runs = JsonConvert.DeserializeObject <IEnumerable <Run> >(Resources.Runs); context.Runs.AddRange(runs); context.SaveChanges(); } if (!context.Characters.Any()) { var characters = JsonConvert.DeserializeObject <IEnumerable <Character> >(Resources.Characters); context.Characters.AddRange(characters); context.SaveChanges(); } if (!context.Leaderboards.Any()) { var leaderboards = JsonConvert.DeserializeObject <IEnumerable <Leaderboard> >(Resources.Leaderboards); context.Leaderboards.AddRange(leaderboards); context.SaveChanges(); } if (!context.DailyLeaderboards.Any()) { var dailyLeaderboards = JsonConvert.DeserializeObject <IEnumerable <DailyLeaderboard> >(Resources.DailyLeaderboards); context.DailyLeaderboards.AddRange(dailyLeaderboards); context.SaveChanges(); } } }