Add sqlite database
This commit is contained in:
@@ -7,10 +7,16 @@ namespace EstusShots.Server.Services
|
||||
{
|
||||
public EstusShotsContext(DbContextOptions options) : base(options)
|
||||
{
|
||||
ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||
Database.EnsureCreated();
|
||||
}
|
||||
|
||||
public DbSet<Season> Seasons { get; set; } = default!;
|
||||
public DbSet<Episode> Episodes { get; set; } = default!;
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Season>().ToTable(nameof(Season));
|
||||
modelBuilder.Entity<Episode>().ToTable(nameof(Episode));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,11 @@ namespace EstusShots.Server
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddDbContext<EstusShotsContext>(
|
||||
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(); });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,5 +6,8 @@
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"Sqlite": "DataSource=debug.db;"
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user