/// <summary> /// Create and, if empty, seed database /// </summary> /// <param name="context">The DbContext</param> public static void Initialise(AccessLogContext context) { context.Database.EnsureCreated(); if (context.AccessLogs.Any()) { return; } Seed(context); }
/// <summary> /// Add some initial seed data to the database /// </summary> /// <param name="context">The DbContext</param> public static void Seed(AccessLogContext context) { List <AccessLog> accessLogs = new List <AccessLog> { new AccessLog { SubmittedDateTime = DateTime.Now.AddHours(-1), UserName = "******", EmailAddress = "*****@*****.**", DOB = DateTime.Now.AddYears(-20), IsSuccess = true, IsLockedOut = false }, new AccessLog { SubmittedDateTime = DateTime.Now.AddHours(-2), UserName = "******", EmailAddress = "*****@*****.**", DOB = DateTime.Now.AddYears(-10), IsSuccess = false, IsLockedOut = false }, new AccessLog { SubmittedDateTime = DateTime.Now.AddHours(-3), UserName = "******", EmailAddress = "*****@*****.**", DOB = DateTime.Now.AddYears(-30), IsSuccess = true, IsLockedOut = false } }; context.AccessLogs.AddRange(accessLogs); context.SaveChanges(); }