You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// the db Context publicclassApplicationDbContext:DbContext,IApplicationDbContext{publicApplicationDbContext(DbContextOptions<ApplicationDbContext>options):base(options){}publicDbSet<RadariaData>Dataset{get;set;}}publicclassMatch{// don't forget to add a IdpublicintId{get;set;}publicstringName{get;set;}publicIEnumerable<GameSituation>Situations{get;set;}// relation to containing MatchespublicintDatasetId{get;set;}publicRadariaDataDataset{get;set;}}publicclassRadariaData{publicintId{get;set;}publicIEnumerable<Match>Matches{get;set;}}}
Initialize DB Code first
Create init method and call it at the end of the ConfigureServices (Startup.cs) - InitializeDatabase(services);
privatestaticvoidInitializeDatabase(IServiceCollectionservices){// avoid init when called from migration creationif("ef"==Assembly.GetEntryAssembly().GetName().Name.ToLower(CultureInfo.InvariantCulture)){return;}staticvoidMigrate(DbContextcontext){// f.e. when using in unit testenvironmentif(context.Database.ProviderName!="Microsoft.EntityFrameworkCore.InMemory"){context.Database.Migrate();}}usingvarserviceProvider=services.BuildServiceProvider();varappCtx=serviceProvider.GetRequiredService<ApplicationDbContext>();Migrate(appCtx);}
Create migration method (call it at end of end of configure (Startup.cs) MigrateDatabase(app);)