Database parts koded

This commit is contained in:
2026-02-07 14:27:50 +01:00
parent 20e3e022d6
commit 4a5fb36b8e
4 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,11 @@
using Microsoft.EntityFrameworkCore;
using VideoGameCharacterApi.Models;
namespace VideoGameCharacterApi.Data;
public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options):DbContext(options)
{
public DbSet<Character> Characters => Set<Character>();
}

View File

@ -9,6 +9,9 @@ builder.Services.AddControllers();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi(); builder.Services.AddOpenApi();
builder.services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddScoped<IVideoGameCharacterService, VideoGameCharacterService>(); builder.Services.AddScoped<IVideoGameCharacterService, VideoGameCharacterService>();
var app = builder.Build(); var app = builder.Build();

View File

@ -8,6 +8,12 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.2" /> <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Scalar.AspNetCore" Version="2.12.32" /> <PackageReference Include="Scalar.AspNetCore" Version="2.12.32" />
</ItemGroup> </ItemGroup>

View File

@ -1,4 +1,8 @@
{ {
"ConnectionStrings": {
"DefaultConnection": ""
"Server=TFOACERLAP;Database=VideoGameCharactersDB;Trusted_Connection=True;Encrypt=no;MultipleActiveResultSets=true\"\"",
},
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information",