public void UpdateSpecialEvent(SpecialEvent Entities) { using(RestaurantContext specialEventDBContext = new RestaurantContext()) { var updating = specialEventDBContext.SpecialEvents.Attach(Entities); var matchingWithExistingValues = specialEventDBContext.Entry<SpecialEvent>(updating); matchingWithExistingValues.State = System.Data.Entity.EntityState.Modified; specialEventDBContext.SaveChanges(); } }
public void DeleteSpecialEvent(SpecialEvent Entities) { using(RestaurantContext specialEventDBContext = new RestaurantContext()) { var existingvalue = specialEventDBContext.SpecialEvents.Find(Entities.EventCode); // remember to add the DataKeyNames for delete and update specialEventDBContext.SpecialEvents.Remove(existingvalue); specialEventDBContext.SaveChanges(); } }
public void InsertSpecialEvent(SpecialEvent item) { using (RestaurantContext context = new RestaurantContext()) { //Add the item to the DBcontext var added = context.SpecialEvents.Add(item); //PS we arent really going to do anything with the variable 'added', I just want you to be aware that the Add() method will return the newly added object. (This can be useful in other situations, which we will see later) //Save the changes to the database context.SaveChanges(); } }
public void AddSpecialEvent(SpecialEvent item) { using (var context = new RestaurantContext()) { //add the item to dbcontext var added = context.SpecialEvents.Add(item); //p.s. - we aren't really going to do anything with the variable 'added; // i just want you to be aware that the Add() METHOD will return the //newly added object. (this can be useful in other situations, which we will see later) //save changes context.SaveChanges(); } }
public void DeleteSpecialEvent(SpecialEvent item) { using (var context = new RestaurantContext()) { // First, get a reference to the actual item in the Db // Find() is a method to look up an item by it's primary key. var existing = context.SpecialEvents.Find(item.EventCode); // Second, remove the item from the database context context.SpecialEvents.Remove(existing); // Lastly, save the changes to the database context.SaveChanges(); } }
public void AddSpecialEvent(SpecialEvent item) { using (var context = new RestaurantContext()) { //Add the new item to the Db context var added = context.SpecialEvents.Add(item); //p.s.-we aren't really going to do anything with the variable 'added' //I just want you to be aware that the Add() method will return the //newly added object. ( This can be useful in other situation, which //we will see later.) //Save the changes to the database context.SaveChanges(); } }
public void UpdateSpecialEvent(SpecialEvent item) { using ( RestaurantContext context = new RestaurantContext()) { //First attach the item to the dbContext collection var attached = context.SpecialEvents.Attach(item); //Second,get the entry for existing data that should match for //this specific special event var existing = context.Entry<SpecialEvent>(attached); //Third,mark that the object's values have changed existing.State = System.Data.Entity.EntityState.Modified; //Lastly,save the changes in the database context.SaveChanges(); } }
public void DeleteSpecialEvent(SpecialEvent item) { using (var context = new RestaurantContext()) { //first get a reference to the actual item by its primary key //find() is a METHOD to look up an utem by its primary key. var existing = context.SpecialEvents.Find(item.EventCode); //second, remove the item from the database context context.SpecialEvents.Remove(existing); //lastly, save the changes to the database context.SaveChanges(); } }
public void DeactivateSpecialEvent(SpecialEvent item) { using (var context = new RestaurantContext()) { // First, get a reference to the actual item in the Db // Find() is a method to look up an item by it's primary key. var existing = context.SpecialEvents.Find(item.EventCode); // Second, remove the item from the database context existing.Active = false; // Modifies the property on the SpecialEvent var updatable = context.Entry(existing); // Get a reference to the special event as an Entity in the database context // Specify a particular property as being changed. updatable.Property(x => x.Active).IsModified = true; // Lastly, save the changes to the database context.SaveChanges(); } }
public void UpdateSpecialEvent(SpecialEvent item) { using (RestaurantContext context = new RestaurantContext()) { //First attach the item to the dbContext collection var attached = context.SpecialEvents.Attach(item); // var matchingWithExistingValues = context.Entry<SpecialEvent>(attached); //matchingWithExistingValues.State = System.Data.Entity.EntityState.Modified; //context.SaveChanges(); var existing = context.Entry<SpecialEvent>(attached); existing.State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } //First attacj the item to the dbContext collection }
public void AddSpecialEvent(SpecialEvent Entities) { using (RestaurantContext specialEventDBContext = new RestaurantContext()) { var adding = specialEventDBContext.SpecialEvents.Add(Entities); specialEventDBContext.SaveChanges(); } }