public IEnumerable <string> Run() { List <string> errorMessages = new List <string>(); Database.SetInitializer(new DropCreateDatabaseAlways <FamilyMembersWithAttributes>()); var context = new FamilyMembersWithAttributes(); var chris = new Dad() { FirstName = "Chris this is a really long name........", Address = new Address() }; try { context.Dads.Add(chris); errorMessages.AddRange(ValidationHelper.ExtractValidationMessages(context)); context.SaveChanges(); } catch (DbEntityValidationException ex) { errorMessages.Add("Exception thrown when trying to save dad " + ex.ToString()); } return(errorMessages); }
public IEnumerable <string> Run() { List <string> errorMessages = new List <string>(); Database.SetInitializer(new DropCreateDatabaseAlways <FamilyMembersWithAttributes>()); var context = new FamilyMembersWithAttributes(); var chris = new Dad() { FirstName = "Chris", Address = new Address() { City = "Ethan", State = "SD", Zip = "9999999999" } }; var otherDad = new Dad() { FirstName = "Dad with short zip code", Address = new Address() { Zip = "1" } }; try { context.Dads.Add(chris); context.Dads.Add(otherDad); errorMessages.AddRange(ValidationHelper.ExtractValidationMessages(context)); context.SaveChanges(); } catch (DbEntityValidationException ex) { errorMessages.Add("Exception thrown when trying to save dad " + ex.ToString()); } return(errorMessages); }
protected override void Seed(FamilyMembersWithAttributes context) { var chris = context.Dads.Include(x => x.Kids).FirstOrDefault(x => x.FirstName == "Chris"); if (chris != null) { chris.Kids.Clear(); context.Dads.Remove(chris); } context.SaveChanges(); var ethan = new Address() { City = "Ethan", State = "SD", Zip = "57334" }; chris = new Dad { FirstName = "Chris", DayOfBirth = new DateTime(1979, 12, 6), Address = ethan, Kids = new List <Kid> { new Kid() { Name = "Damon", Birthday = DateTime.Parse("12/4/2003"), }, new Kid() { Name = "Mason", Birthday = DateTime.Parse("2/27/2005"), } } }; context.Dads.Add(chris); base.Seed(context); }