private static void GetCarHolderAndAddCar(IServiceProvider serviceProvider) { using SampleContext context = serviceProvider.GetRequiredService <SampleContext>(); CarHolder carHolder = context.CarHolders.First(); Car car = new Car("Skoda Fabia", new Specs(4, 1035, 90)); carHolder.AddCar(car); Console.WriteLine($"Adding {car.Name} ({car.Specs}) to {carHolder.Name}"); Console.WriteLine(); }
private static void AddCarHolders(IServiceProvider serviceProvider) { using SampleContext context = serviceProvider.GetRequiredService <SampleContext>(); CarHolder carHolder1 = new CarHolder("Christopher"); carHolder1.AddCar(new Car("Opel Meriva", new Specs(4, 1455, 120))); context.CarHolders.Add(carHolder1); CarHolder carHolder2 = new CarHolder("Christoph"); carHolder2.AddCar(new Car("Tesla Model 3", new Specs(4, 1906, 440))); context.CarHolders.Add(carHolder2); context.SaveChanges(); }