public async Task Seed() { _ctx.Database.EnsureCreated(); var user = await _userManager.FindByEmailAsync("*****@*****.**"); if (user == null) { user = new AppUser() { FirstName = "Andre", LastName = "Lashley", UserName = "******", Email = "*****@*****.**" }; var result = await _userManager.CreateAsync(user, "P@ssw0rd!"); if (result != IdentityResult.Success) { throw new InvalidOperationException("Failed to create default user."); } } if (!_ctx.Restaurants.Any()) { // Need to create sample data var filePath = Path.Combine(_hosting.ContentRootPath, "Data/restaurants.json"); var json = File.ReadAllText(filePath); var restaurants = JsonConvert.DeserializeObject <IEnumerable <Restaurant> >(json); _ctx.Restaurants.AddRange(restaurants); _ctx.SaveChanges(); } }
public int Commit() { // This will combine all the db operations, that may involve multiple tables, // into one transaction, and perform them atomically. // // returns the number of updated rows return(db.SaveChanges()); }
public static void Initialize(OdeToFoodDbContext context) { // Look for any movies. if (context.Restaurants.Any()) { return; // DB has been seeded } context.Restaurants.AddRange( new Restaurant { Name = "Scott's Pizza Place", Cuisine = CuisineType.French }, new Restaurant { Name = "Tersiguels", Cuisine = CuisineType.Italian }, new Restaurant { Name = "King's Contrivance", Cuisine = CuisineType.German } ); context.SaveChanges(); }
public int Commit() => Context.SaveChanges();
public int Commit() { return(db.SaveChanges()); // this method returns an int that represents the number of rows affected in db }
public int commit() { // Nothing will .Add or .Remove until SaveChanges is called return(db.SaveChanges()); }
public bool SaveAll() { return(_ctx.SaveChanges() > 0); }
public int Commit() => db.SaveChanges();
public int Commit() { return(odeToFoodDbContext.SaveChanges()); }
public int Commit() { /*With EF on the DbContext there's a method SaveChanges [Invoke this method -> it returns an integer which represents no of * rows affected in the db so we retrun a value returned by SaveChanges()]*/ return(db.SaveChanges()); }
public int Commit() { return(_db.SaveChanges()); //no of rows... }
public int Commit() { //Returns how many rows been affected return(_db.SaveChanges()); }
public int Commit() { db.SaveChanges(); return(1); }
public Restaurant AddRestaurant(Restaurant addNewRestaurant) { db.Add(addNewRestaurant); db.SaveChanges(); return(addNewRestaurant); }
public int Commit() { //this method returns the number of rows affected by the changes return(db.SaveChanges()); }
public int Commit() { return(dbContext.SaveChanges()); }
public int Commit() { //NOTE: nothing is changed until Commit is invoked return(db.SaveChanges()); //returns an int that represents # of rows affected in the db }
public int Commit() { //Return number of rows affected in database return(db.SaveChanges()); }
public int Commit() { return(db.SaveChanges()); //SaveChanges is a method built into DbContext class. //your adds, edits and deletes don't actually happen until Commit() is called. }
public int Commit() { return(db.SaveChanges()); }
public int Commit() { return(db.SaveChanges()); //this changes occur atomitically }