예제 #1
0
        private static void RemoveRecord()
        {
            using (AutoLotEntities context = new AutoLotEntities())
            {
                //Define a key for entity we are looking for...
                EntityKey key = new EntityKey("AutoLotEntities.Cars", "CarID", 2222);

                //see if we have key, and delete if we do
                Car carToDelete = (Car)context.GetObjectByKey(key);
                if(carToDelete != null)
                {
                    context.DeleteObject(carToDelete);
                    context.SaveChanges();
                }
            }
        }
예제 #2
0
 private static void AddNewRecord()
 {
     using (AutoLotEntities context = new AutoLotEntities())
     {
         try
         {
             context.Cars.AddObject(new Car() { CarID = 2222, Make = "BMW", Color = "Silver"});
             context.Cars.AddObject(new Car() { CarID = 2222, Make = "Mercedes", Color = "Yellow" });
             context.SaveChanges();
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.InnerException.Message);
         }
     }
 }