From a982b15cbe507e33348781235693e16bbd06258e Mon Sep 17 00:00:00 2001 From: luxick Date: Sat, 29 Feb 2020 18:45:10 +0100 Subject: [PATCH] Add sqlite database --- .gitignore | 3 ++- EstusShots.Server/Services/EstusShotsContext.cs | 8 +++++++- EstusShots.Server/Startup.cs | 8 ++++++-- EstusShots.Server/appsettings.json | 3 +++ EstusShots.sln.DotSettings.user | 3 ++- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 53569f9..25f0bd3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ bin/ obj/ /packages/ *.blob -.idea/ \ No newline at end of file +.idea/ +*.db \ No newline at end of file diff --git a/EstusShots.Server/Services/EstusShotsContext.cs b/EstusShots.Server/Services/EstusShotsContext.cs index d397451..e202ae2 100644 --- a/EstusShots.Server/Services/EstusShotsContext.cs +++ b/EstusShots.Server/Services/EstusShotsContext.cs @@ -7,10 +7,16 @@ namespace EstusShots.Server.Services { public EstusShotsContext(DbContextOptions options) : base(options) { - ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; + Database.EnsureCreated(); } public DbSet Seasons { get; set; } = default!; public DbSet Episodes { get; set; } = default!; + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().ToTable(nameof(Season)); + modelBuilder.Entity().ToTable(nameof(Episode)); + } } } \ No newline at end of file diff --git a/EstusShots.Server/Startup.cs b/EstusShots.Server/Startup.cs index 454ae34..3772acd 100644 --- a/EstusShots.Server/Startup.cs +++ b/EstusShots.Server/Startup.cs @@ -25,7 +25,11 @@ namespace EstusShots.Server public void ConfigureServices(IServiceCollection services) { services.AddDbContext( - opt => opt.UseInMemoryDatabase("debug.db")); + opt => + { + opt.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking); + opt.UseSqlite(Configuration.GetConnectionString("Sqlite")); + }); services.AddAutoMapper(typeof(Startup)); services.AddControllers().AddJsonOptions(options => { @@ -57,6 +61,7 @@ namespace EstusShots.Server { app.UseHttpsRedirection(); } + // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger(); @@ -69,7 +74,6 @@ namespace EstusShots.Server app.UseRouting(); app.UseAuthorization(); - app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); } } diff --git a/EstusShots.Server/appsettings.json b/EstusShots.Server/appsettings.json index d9d9a9b..060eaf3 100644 --- a/EstusShots.Server/appsettings.json +++ b/EstusShots.Server/appsettings.json @@ -6,5 +6,8 @@ "Microsoft.Hosting.Lifetime": "Information" } }, + "ConnectionStrings": { + "Sqlite": "DataSource=debug.db;" + }, "AllowedHosts": "*" } diff --git a/EstusShots.sln.DotSettings.user b/EstusShots.sln.DotSettings.user index d8f3332..6a9efe0 100644 --- a/EstusShots.sln.DotSettings.user +++ b/EstusShots.sln.DotSettings.user @@ -1,3 +1,4 @@  True - True \ No newline at end of file + True + True \ No newline at end of file