Database parts koded
This commit is contained in:
11
VideoGameCharacterApi/Data/ApplicationDbContext.cs
Normal file
11
VideoGameCharacterApi/Data/ApplicationDbContext.cs
Normal 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>();
|
||||
}
|
||||
@ -9,6 +9,9 @@ builder.Services.AddControllers();
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
builder.services.AddDbContext<ApplicationDbContext>(options =>
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
|
||||
|
||||
builder.Services.AddScoped<IVideoGameCharacterService, VideoGameCharacterService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
@ -8,6 +8,12 @@
|
||||
|
||||
<ItemGroup>
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": ""
|
||||
"Server=TFOACERLAP;Database=VideoGameCharactersDB;Trusted_Connection=True;Encrypt=no;MultipleActiveResultSets=true\"\"",
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
|
||||
Reference in New Issue
Block a user