using Aps_Single_Page_Anwendung.Models; using Aps_Single_Page_Anwendung.Repositories; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using System; using System.Linq; namespace Single_Page_Anwendung.Models { public class DatenEinlesen { public static void Initialize(IServiceProvider serviceProvider) { // Holy shit Oo using (var futterContext = new FutterContext(serviceProvider.GetRequiredService>())) { if (futterContext.Speisen.Any()) { return; } var kategorieRepository = new FileKategorieRepository(serviceProvider.GetRequiredService()); var kategorien = kategorieRepository.GetKategorien().ToList(); kategorien.ForEach(k => { k.Id = 0; foreach (var speise in k.Speisen) { speise.Id = 0; speise.KategorieId = 0; } }); futterContext.Kategorien.AddRange(kategorien); futterContext.SaveChanges(); } } } }