private static void AddNewCars(IEnumerable <Car> carsToAdd) { using (var context = new AutoLotEntities()) { context.Cars.AddRange(carsToAdd); context.SaveChanges(); } }
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); } } }