added DataContext.cs

This commit is contained in:
Вячеслав 2025-03-14 22:47:19 +05:00
parent 4e3c3e6149
commit 7d06084dfb
6 changed files with 50 additions and 4 deletions

View file

@ -0,0 +1,17 @@
using Microsoft.EntityFrameworkCore;
using SurveyLib.Core.Models;
namespace SurveyLib.Infrastructure.EFCore.Data;
public class DataContext : DbContext
{
public DbSet<Survey> Surveys { get; set; }
public DbSet<QuestionBase> Questions { get; set; }
public DbSet<Completion> Completions { get; set; }
public DbSet<Answer> Answers { get; set; }
public DataContext(DbContextOptions<DataContext> options) : base(options)
{
Database.EnsureCreated();
}
}

View file

@ -1,10 +1,19 @@
using SurveyLib.Core.Models; using SurveyLib.Core.Models;
using SurveyLib.Core.Repositories; using SurveyLib.Core.Repositories;
using Microsoft.EntityFrameworkCore;
using SurveyLib.Infrastructure.EFCore.Data;
namespace SurveyLib.Infrastructure.EFCore.Repositories; namespace SurveyLib.Infrastructure.EFCore.Repositories;
public class AnswerRepository : IAnswerRepository public class AnswerRepository : IAnswerRepository
{ {
private readonly DataContext _context;
public AnswerRepository(DataContext context)
{
_context = context;
}
public Task<Answer>? GetByIdAsync(int id) public Task<Answer>? GetByIdAsync(int id)
{ {
throw new NotImplementedException(); throw new NotImplementedException();

View file

@ -1,10 +1,18 @@
using SurveyLib.Core.Models; using SurveyLib.Core.Models;
using SurveyLib.Core.Repositories; using SurveyLib.Core.Repositories;
using SurveyLib.Infrastructure.EFCore.Data;
namespace SurveyLib.Infrastructure.EFCore.Repositories; namespace SurveyLib.Infrastructure.EFCore.Repositories;
public class CompletionRepository : ICompletionRepository public class CompletionRepository : ICompletionRepository
{ {
private readonly DataContext _context;
public CompletionRepository(DataContext context)
{
_context = context;
}
public Task<Completion>? GetByIdAsync(int id) public Task<Completion>? GetByIdAsync(int id)
{ {
throw new NotImplementedException(); throw new NotImplementedException();

View file

@ -1,10 +1,18 @@
using SurveyLib.Core.Models; using SurveyLib.Core.Models;
using SurveyLib.Core.Repositories; using SurveyLib.Core.Repositories;
using SurveyLib.Infrastructure.EFCore.Data;
namespace SurveyLib.Infrastructure.EFCore.Repositories; namespace SurveyLib.Infrastructure.EFCore.Repositories;
public class QuestionRepository : IQuestionRepository public class QuestionRepository : IQuestionRepository
{ {
private readonly DataContext _context;
public QuestionRepository(DataContext context)
{
_context = context;
}
public Task<QuestionBase>? GetByIdAsync(int id) public Task<QuestionBase>? GetByIdAsync(int id)
{ {
throw new NotImplementedException(); throw new NotImplementedException();

View file

@ -1,10 +1,18 @@
using SurveyLib.Core.Models; using SurveyLib.Core.Models;
using SurveyLib.Core.Repositories; using SurveyLib.Core.Repositories;
using SurveyLib.Infrastructure.EFCore.Data;
namespace SurveyLib.Infrastructure.EFCore.Repositories; namespace SurveyLib.Infrastructure.EFCore.Repositories;
public class SurveyRepository : ISurveyRepository public class SurveyRepository : ISurveyRepository
{ {
private readonly DataContext _context;
public SurveyRepository(DataContext context)
{
_context = context;
}
public Task<Survey>? GetByIdAsync(int id) public Task<Survey>? GetByIdAsync(int id)
{ {
throw new NotImplementedException(); throw new NotImplementedException();

View file

@ -6,10 +6,6 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Folder Include="Data\" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.3" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.3" />
</ItemGroup> </ItemGroup>