From 489f0ee35a2e0ad89c44369116467b9de5672365 Mon Sep 17 00:00:00 2001 From: Gulum Date: Tue, 17 Oct 2023 01:18:17 +0200 Subject: [PATCH] Introduce EF --- ApplicationContext.cs | 12 ++++++++++++ GerbilManager.csproj | 2 ++ Program.cs | 4 ++++ appsettings.Development.json | 3 +++ appsettings.json | 3 +++ 5 files changed, 24 insertions(+) create mode 100644 ApplicationContext.cs diff --git a/ApplicationContext.cs b/ApplicationContext.cs new file mode 100644 index 0000000..0b5dcfa --- /dev/null +++ b/ApplicationContext.cs @@ -0,0 +1,12 @@ +using GerbilManager.Models; +using Microsoft.EntityFrameworkCore; + +public class ApplicationContext : DbContext +{ + public ApplicationContext(DbContextOptions options) + :base(options) + { + } + public DbSet Gerbils { get; set; } +} + diff --git a/GerbilManager.csproj b/GerbilManager.csproj index 7429eed..d6fce08 100644 --- a/GerbilManager.csproj +++ b/GerbilManager.csproj @@ -8,6 +8,8 @@ + + diff --git a/Program.cs b/Program.cs index 8ad3f5f..e5bf8b1 100644 --- a/Program.cs +++ b/Program.cs @@ -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(); +builder.Services.AddDbContext(opts => opts.UseSqlServer(Configuration.GetConnectionString("sqlConnection"))); + var app = builder.Build(); + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { diff --git a/appsettings.Development.json b/appsettings.Development.json index ff66ba6..138e433 100644 --- a/appsettings.Development.json +++ b/appsettings.Development.json @@ -4,5 +4,8 @@ "Default": "Information", "Microsoft.AspNetCore": "Warning" } + }, + "ConnectionStrings": { + "sqlConnection": "server=.; database=GerbilManagerDebug; Integrated Security=true" } } diff --git a/appsettings.json b/appsettings.json index 4d56694..77b42a0 100644 --- a/appsettings.json +++ b/appsettings.json @@ -5,5 +5,8 @@ "Microsoft.AspNetCore": "Warning" } }, + "ConnectionStrings": { + "sqlConnection": "server=.; database=GerbilManager; Integrated Security=true" + }, "AllowedHosts": "*" }