protected override void Seed(CityGamesContext context) { context.Levels.Add(new Level { ExpRequired = 1, Id = 1, Name = "Newbie" }); context.Levels.Add(new Level { ExpRequired = 100, Id = 2, Name = "Jar" }); context.Levels.Add(new Level { ExpRequired = 200, Id = 3, Name = "Siren" }); context.Levels.Add(new Level { ExpRequired = 1000, Id = 4, Name = "Boss" }); GenerateRoles(context); context.SaveChanges(); }
public void Save() { try { context.SaveChanges(); } catch (DbEntityValidationException e) { var outputLines = new List <string>(); foreach (var eve in e.EntityValidationErrors) { outputLines.Add($"{DateTime.Now}: Entity of type \"{eve.Entry.Entity.GetType().Name}\" in state \"{eve.Entry.State}\" has the following validation errors:"); outputLines.AddRange(eve.ValidationErrors.Select(ve => $"- Property: \"{ve.PropertyName}\", Error: \"{ve.ErrorMessage}\"")); } System.IO.File.AppendAllLines(@"C:\errors.txt", outputLines); throw; } }