using (var context = new VaporStoreDbContext()) { var game = new Game { Name = "Call of Duty" }; context.Games.Add(game); var user = new User { Name = "John", Email = "[email protected]" }; context.Users.Add(user); var purchase = new Purchase { GameId = game.Id, UserId = user.Id, Date = DateTime.Now }; context.Purchases.Add(purchase); context.SaveChanges(); }
using (var context = new VaporStoreDbContext()) { var game = context.Games.FirstOrDefault(g => g.Name == "Call of Duty"); game.Price = 49.99; var user = context.Users.FirstOrDefault(u => u.Email == "[email protected]"); user.Credits -= 49.99M; context.SaveChanges(); }In this example, we retrieve an existing game and user from the database and update their prices and credits respectively. We then call the SaveChanges method to save the changes to the database. Overall, VaporStoreDbContext SaveChanges is an important method for saving changes made to the database context in .NET using Entity Framework Core library.