static void Main() { Database.SetInitializer(new MigrateDatabaseToLatestVersion<CarsSystemDbContext, Configuration>()); var db = new CarsSystemDbContext(); //db.Cars.Add(new Car()); // Needed to create the database. var carsCollection = GetCarsCollectionFromJson("../../../../cars-system.json"); SendCarsCollectionToDatabase(carsCollection, db); }
private static void SendCarsCollectionToDatabase(List<CarView> carsCollection, CarsSystemDbContext db) { var cities = new Dictionary<string, City>(); var manufacturers = new Dictionary<string, Manufacturer>(); var dealers = new Dictionary<string, Dealer>(); foreach (var car in carsCollection) { db.Cars.Add(GetCarFromCarView(car, manufacturers, dealers, cities)); } db.SaveChanges(); }