Esempio n. 1
0
 private static void AddNewCars(IEnumerable <Car> carsToAdd)
 {
     using (var context = new AutoLotEntities())
     {
         context.Cars.AddRange(carsToAdd);
         context.SaveChanges();
     }
 }
Esempio n. 2
0
        private static int AddNewCar(Car car)
        {
            using (AutoLotEntities context = new AutoLotEntities())
            {
                try
                {
                    context.Cars.Add(car);

                    context.SaveChanges();

                    // On a successful save, EF populates the database generated identity field.
                    return(car.CarId);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.InnerException?.Message);
                    return(0);
                }
            }
        }