Introduce EF

This commit is contained in:
2023-10-17 01:18:17 +02:00
parent 8a2995302a
commit 489f0ee35a
5 changed files with 24 additions and 0 deletions

12
ApplicationContext.cs Normal file
View File

@@ -0,0 +1,12 @@
using GerbilManager.Models;
using Microsoft.EntityFrameworkCore;
public class ApplicationContext : DbContext
{
public ApplicationContext(DbContextOptions options)
:base(options)
{
}
public DbSet<Gerbil> Gerbils { get; set; }
}

View File

@@ -8,6 +8,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.12" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

View File

@@ -1,4 +1,5 @@
using GerbilManager.Repositories;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
@@ -11,8 +12,11 @@ builder.Services.AddSwaggerGen();
builder.Services.AddSingleton<IGerbilRepository, InMemGerbilRepository>();
builder.Services.AddDbContext<ApplicationContext>(opts => opts.UseSqlServer(Configuration.GetConnectionString("sqlConnection")));
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{

View File

@@ -4,5 +4,8 @@
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"sqlConnection": "server=.; database=GerbilManagerDebug; Integrated Security=true"
}
}

View File

@@ -5,5 +5,8 @@
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"sqlConnection": "server=.; database=GerbilManager; Integrated Security=true"
},
"AllowedHosts": "*"
}