From 4a5fb36b8ecab053ac916801d0d7cec718adb20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Sat, 7 Feb 2026 14:27:50 +0100 Subject: [PATCH] Database parts koded --- VideoGameCharacterApi/Data/ApplicationDbContext.cs | 11 +++++++++++ VideoGameCharacterApi/Program.cs | 3 +++ VideoGameCharacterApi/VideoGameCharacterApi.csproj | 6 ++++++ VideoGameCharacterApi/appsettings.json | 4 ++++ 4 files changed, 24 insertions(+) create mode 100644 VideoGameCharacterApi/Data/ApplicationDbContext.cs diff --git a/VideoGameCharacterApi/Data/ApplicationDbContext.cs b/VideoGameCharacterApi/Data/ApplicationDbContext.cs new file mode 100644 index 0000000..8b5c338 --- /dev/null +++ b/VideoGameCharacterApi/Data/ApplicationDbContext.cs @@ -0,0 +1,11 @@ +using Microsoft.EntityFrameworkCore; +using VideoGameCharacterApi.Models; + +namespace VideoGameCharacterApi.Data; + +public class ApplicationDbContext(DbContextOptions options):DbContext(options) +{ + + + public DbSet Characters => Set(); +} diff --git a/VideoGameCharacterApi/Program.cs b/VideoGameCharacterApi/Program.cs index c0035fc..2a1acb3 100644 --- a/VideoGameCharacterApi/Program.cs +++ b/VideoGameCharacterApi/Program.cs @@ -9,6 +9,9 @@ builder.Services.AddControllers(); // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi builder.Services.AddOpenApi(); +builder.services.AddDbContext(options => + options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"))); + builder.Services.AddScoped(); var app = builder.Build(); diff --git a/VideoGameCharacterApi/VideoGameCharacterApi.csproj b/VideoGameCharacterApi/VideoGameCharacterApi.csproj index fd42fea..6e4bfee 100644 --- a/VideoGameCharacterApi/VideoGameCharacterApi.csproj +++ b/VideoGameCharacterApi/VideoGameCharacterApi.csproj @@ -8,6 +8,12 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/VideoGameCharacterApi/appsettings.json b/VideoGameCharacterApi/appsettings.json index 10f68b8..d2a3663 100644 --- a/VideoGameCharacterApi/appsettings.json +++ b/VideoGameCharacterApi/appsettings.json @@ -1,4 +1,8 @@ { + "ConnectionStrings": { + "DefaultConnection": "" + "Server=TFOACERLAP;Database=VideoGameCharactersDB;Trusted_Connection=True;Encrypt=no;MultipleActiveResultSets=true\"\"", + }, "Logging": { "LogLevel": { "Default": "Information",