diff --git a/SurveyLib.Infrastructure.EFCore/Data/DataContext.cs b/SurveyLib.Infrastructure.EFCore/Data/DataContext.cs new file mode 100644 index 0000000..dcc2e68 --- /dev/null +++ b/SurveyLib.Infrastructure.EFCore/Data/DataContext.cs @@ -0,0 +1,17 @@ +using Microsoft.EntityFrameworkCore; +using SurveyLib.Core.Models; + +namespace SurveyLib.Infrastructure.EFCore.Data; + +public class DataContext : DbContext +{ + public DbSet Surveys { get; set; } + public DbSet Questions { get; set; } + public DbSet Completions { get; set; } + public DbSet Answers { get; set; } + + public DataContext(DbContextOptions options) : base(options) + { + Database.EnsureCreated(); + } +} \ No newline at end of file diff --git a/SurveyLib.Infrastructure.EFCore/Repositories/AnswerRepository.cs b/SurveyLib.Infrastructure.EFCore/Repositories/AnswerRepository.cs index 3906537..d9a78c6 100644 --- a/SurveyLib.Infrastructure.EFCore/Repositories/AnswerRepository.cs +++ b/SurveyLib.Infrastructure.EFCore/Repositories/AnswerRepository.cs @@ -1,10 +1,19 @@ using SurveyLib.Core.Models; using SurveyLib.Core.Repositories; +using Microsoft.EntityFrameworkCore; +using SurveyLib.Infrastructure.EFCore.Data; namespace SurveyLib.Infrastructure.EFCore.Repositories; public class AnswerRepository : IAnswerRepository { + private readonly DataContext _context; + + public AnswerRepository(DataContext context) + { + _context = context; + } + public Task? GetByIdAsync(int id) { throw new NotImplementedException(); diff --git a/SurveyLib.Infrastructure.EFCore/Repositories/CompletionRepository.cs b/SurveyLib.Infrastructure.EFCore/Repositories/CompletionRepository.cs index c628977..83c2705 100644 --- a/SurveyLib.Infrastructure.EFCore/Repositories/CompletionRepository.cs +++ b/SurveyLib.Infrastructure.EFCore/Repositories/CompletionRepository.cs @@ -1,10 +1,18 @@ using SurveyLib.Core.Models; using SurveyLib.Core.Repositories; +using SurveyLib.Infrastructure.EFCore.Data; namespace SurveyLib.Infrastructure.EFCore.Repositories; public class CompletionRepository : ICompletionRepository { + private readonly DataContext _context; + + public CompletionRepository(DataContext context) + { + _context = context; + } + public Task? GetByIdAsync(int id) { throw new NotImplementedException(); diff --git a/SurveyLib.Infrastructure.EFCore/Repositories/QuestionRepository.cs b/SurveyLib.Infrastructure.EFCore/Repositories/QuestionRepository.cs index d193671..eb3403b 100644 --- a/SurveyLib.Infrastructure.EFCore/Repositories/QuestionRepository.cs +++ b/SurveyLib.Infrastructure.EFCore/Repositories/QuestionRepository.cs @@ -1,10 +1,18 @@ using SurveyLib.Core.Models; using SurveyLib.Core.Repositories; +using SurveyLib.Infrastructure.EFCore.Data; namespace SurveyLib.Infrastructure.EFCore.Repositories; public class QuestionRepository : IQuestionRepository { + private readonly DataContext _context; + + public QuestionRepository(DataContext context) + { + _context = context; + } + public Task? GetByIdAsync(int id) { throw new NotImplementedException(); diff --git a/SurveyLib.Infrastructure.EFCore/Repositories/SurveyRepository.cs b/SurveyLib.Infrastructure.EFCore/Repositories/SurveyRepository.cs index 67e3295..4aeb17e 100644 --- a/SurveyLib.Infrastructure.EFCore/Repositories/SurveyRepository.cs +++ b/SurveyLib.Infrastructure.EFCore/Repositories/SurveyRepository.cs @@ -1,10 +1,18 @@ using SurveyLib.Core.Models; using SurveyLib.Core.Repositories; +using SurveyLib.Infrastructure.EFCore.Data; namespace SurveyLib.Infrastructure.EFCore.Repositories; public class SurveyRepository : ISurveyRepository { + private readonly DataContext _context; + + public SurveyRepository(DataContext context) + { + _context = context; + } + public Task? GetByIdAsync(int id) { throw new NotImplementedException(); diff --git a/SurveyLib.Infrastructure.EFCore/SurveyLib.Infrastructure.EFCore.csproj b/SurveyLib.Infrastructure.EFCore/SurveyLib.Infrastructure.EFCore.csproj index 1e98149..08f712f 100644 --- a/SurveyLib.Infrastructure.EFCore/SurveyLib.Infrastructure.EFCore.csproj +++ b/SurveyLib.Infrastructure.EFCore/SurveyLib.Infrastructure.EFCore.csproj @@ -6,10 +6,6 @@ enable - - - -