コード例 #1
0
        public void AddSpecialEvent(SpecialEvent Item)
        {
            using (var context = new RestarauntContext())
            {
                //add item to the dbContext
                var added = context.SpecialEvents.Add(Item);
                //we arent going to do anything with the variable 'added' Just be aware that Add() method will return the newly added object.
                //This can be useful in other situations

                //Save changes to the database
                context.SaveChanges();
            }
        }
コード例 #2
0
 public void DeleteSpecialEvent(SpecialEvent Item)
 {
     using (var context = new RestarauntContext())
     {
         //first get a reference to the actual item in the db
     //find() is a method to lookup an item 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 changes
         context.SaveChanges();
     }
 }
コード例 #3
0
 public void UpdateSpecialEvent(SpecialEvent Item)
 {
     using (RestarauntContext context = new RestarauntContext())
     {
         //first attach the item to the dbContext collection
         var attached = context.SpecialEvents.Attach(Item);
         //second, get the entry for the existing data that should match for this specific special event
         var existing = context.Entry<SpecialEvent>(attached);
         //third, mark that the objects values have changed
         existing.State = System.Data.Entity.EntityState.Modified;
         //lastly, save changes
         context.SaveChanges();
     }
 }