Introduce EF
This commit is contained in:
12
ApplicationContext.cs
Normal file
12
ApplicationContext.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
|
||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.9" />
|
<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" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using GerbilManager.Repositories;
|
using GerbilManager.Repositories;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
@@ -11,8 +12,11 @@ builder.Services.AddSwaggerGen();
|
|||||||
|
|
||||||
builder.Services.AddSingleton<IGerbilRepository, InMemGerbilRepository>();
|
builder.Services.AddSingleton<IGerbilRepository, InMemGerbilRepository>();
|
||||||
|
|
||||||
|
builder.Services.AddDbContext<ApplicationContext>(opts => opts.UseSqlServer(Configuration.GetConnectionString("sqlConnection")));
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,5 +4,8 @@
|
|||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"sqlConnection": "server=.; database=GerbilManagerDebug; Integrated Security=true"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,5 +5,8 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"sqlConnection": "server=.; database=GerbilManager; Integrated Security=true"
|
||||||
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user