public void SpecialEvents_Update(SpecialEvent item) { using (eRestaurantContext context = new eRestaurantContext()) { //indicate the updating item instance //alter the Modified status flag for this instance context.Entry<SpecialEvent>(context.SpecialEvents.Attach(item)).State = System.Data.Entity.EntityState.Modified; //telling it update, SpecialEvent is the entity; //attach is passing in the the item context.SaveChanges(); } }
public void SpecialEvents_Delete(SpecialEvent item) { using (eRestaurantContext context = new eRestaurantContext()) { //lookup the instance and record if found (set pointer to instance) SpecialEvent existing = context.SpecialEvents.Find(item.EventCode); //Setup the comand to execute the delete context.SpecialEvents.Remove(existing); context.SaveChanges(); } #endregion } //eof class
public void SpecialEvents_Add(SpecialEvent item) { using (eRestaurantContext context = new eRestaurantContext()) { //these methods are execute using an instance level item //set up an instance pointer and initialize to null SpecialEvent added = null; //setup the command to execute the add added = context.SpecialEvents.Add(item); //set up command, command is not executed until it is acutally //saved. context.SaveChanges(); } }