public void CleanDatabase() { var ctx = new UserContext(); // Create Fake user Data, this will replace our Database entries. var userList = new List<User> { new User() { Id= 1, Name = "Frederik", PictureUrl = "test" }, new User() { Id=2, Name = "Admin", PictureUrl = "test2" } }; foreach (var user in userList) { var dbUser = ctx.Users.SingleOrDefault(u => u.Name.Equals(user.Name) && u.PictureUrl.Equals(user.PictureUrl)); ctx.Users.Remove(dbUser); } ctx.SaveChanges(); }
public void SeedDatabase() { var ctx = new UserContext(); // Create Fake user Data, this will replace our Database entries. var userList = new List<User> { new User() { Id= 1, Name = "Frederik", PictureUrl = "test" }, new User() { Id=2, Name = "Admin", PictureUrl = "test2" } }; foreach (var user in userList) { ctx.Users.Add(new User() { Name = user.Name, PictureUrl = user.PictureUrl }); } ctx.SaveChanges(); }