Exemplo n.º 1
0
        private static void RemoveRecord()
        {
            // Find a car to delete by primary key.
            using (AutoLotEntities context = new AutoLotEntities())
            {
                // See if we have it?
                var carToDelete =
                    (from c in context.Cars where c.CarID == 2222 select c).FirstOrDefault();

                if (carToDelete != null)
                {
                    context.Cars.Remove(carToDelete);
                    context.SaveChanges();
                }
            }
        }
Exemplo n.º 2
0
        private static void UpdateRecord()
        {
            // Find a car to delete by primary key.
            using (AutoLotEntities context = new AutoLotEntities())
            {
                // Define a key for the entity we are looking for.
                EntityKey key = new EntityKey("AutoLotEntities.Cars", "CarID", 2222);

                // Grab the car, change it, save!
                Car carToUpdate =
                    (from c in context.Cars where c.CarID == 2222 select c).FirstOrDefault();
                if (carToUpdate != null)
                {
                    carToUpdate.Color = "Blue";
                    context.SaveChanges();
                }
            }
        }
Exemplo n.º 3
0
 private static void AddNewRecord()
 {
     // Add record to the Inventory table of the AutoLot
     // database.
     using (AutoLotEntities context = new AutoLotEntities())
     {
         try
         {
             // Hard-code data for a new record, for testing.
             context.Cars.Add(new Car()
             {
                 CarID = 2222,
                 Make  = "Yugo",
                 Color = "Brown"
             });
             context.SaveChanges();
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.InnerException.Message);
         }
     }
 }