diff --git a/API_SQLuedo/DbContextLib/UserDbContext.cs b/API_SQLuedo/DbContextLib/UserDbContext.cs index 6352ab8..b5feec4 100644 --- a/API_SQLuedo/DbContextLib/UserDbContext.cs +++ b/API_SQLuedo/DbContextLib/UserDbContext.cs @@ -12,28 +12,34 @@ namespace DbContextLib public DbSet Inquiry { get; set; } public DbSet InquiryTable { get; set; } public DbSet Lesson { get; set; } - public DbSet ContentLessons { get; set; } public DbSet Paragraph { get; set; } public DbSet Solutions { get; set; } public DbSet Success { get; set; } public DbSet Notepad { get; set; } - public UserDbContext(DbContextOptions options) : base(options) { } + + public UserDbContext(DbContextOptions options) : base(options) + { + } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) { optionsBuilder.UseNpgsql("Host=localhost;Database=SQLuedo;Username=admin;Password=motdepasse"); } + base.OnConfiguring(optionsBuilder); } protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity().HasKey(c => c.LessonId); + // Permet d'avoir les champs de la classe mère dans les classes filles et de ne pas avoir de table pour la classe mère + modelBuilder.Entity().UseTpcMappingStrategy(); + modelBuilder.Entity().HasKey(s => s.UserId); modelBuilder.Entity().HasKey(s => s.InquiryId); modelBuilder.Entity().HasKey(s => s.Id); base.OnModelCreating(modelBuilder); } } -} +} \ No newline at end of file diff --git a/API_SQLuedo/EntityFramework/ContentLessonEntity.cs b/API_SQLuedo/EntityFramework/ContentLessonEntity.cs index ee81947..63ae177 100644 --- a/API_SQLuedo/EntityFramework/ContentLessonEntity.cs +++ b/API_SQLuedo/EntityFramework/ContentLessonEntity.cs @@ -2,14 +2,13 @@ namespace Entities; -[Table("ContentLesson")] public abstract class ContentLessonEntity { public int Id { get; set; } public string ContentContent { get; set; } public string ContentTitle { get; set; } - [ForeignKey(nameof(Lesson))] public int LessonId { get; set; } - public LessonEntity Lesson { get; set; } = null!; + [ForeignKey(nameof(Lesson))] public virtual int LessonId { get; set; } + public virtual LessonEntity Lesson { get; set; } = null!; protected ContentLessonEntity() { diff --git a/API_SQLuedo/StubbedContextLib/StubbedContext.cs b/API_SQLuedo/StubbedContextLib/StubbedContext.cs index e87f12f..0489139 100644 --- a/API_SQLuedo/StubbedContextLib/StubbedContext.cs +++ b/API_SQLuedo/StubbedContextLib/StubbedContext.cs @@ -1,5 +1,4 @@ -using System.Runtime.CompilerServices; -using System.Security.Cryptography; +using System.Security.Cryptography; using DbContextLib; using Entities; using Microsoft.AspNetCore.Cryptography.KeyDerivation; @@ -63,7 +62,25 @@ public class StubbedContext : UserDbContext modelBuilder.Entity().HasData( new SolutionEntity(1, "Maxime", "Sapountzis", "La cuisine", "Le couteau", "Parce que c'est Maxime"), - new SolutionEntity(2, "Johnny", "Ratton", "La cuisine", "Le couteau", "Parce que il est ra****"), + new SolutionEntity(2, "Johnny", "Ratton", "La cuisine", "Le couteau", "Parce que il est fou"), new SolutionEntity(3, "Erwan", "Menager", "La salle de bain", "L'arachide", "Parce que c'est Erwan")); + + modelBuilder.Entity().HasData( + new LessonEntity(1, "La cuisine", "Maxime", new DateOnly(2021, 10, 10)), + new LessonEntity(2, "La salle de bain", "Erwan", new DateOnly(2021, 10, 10)), + new LessonEntity(3, "La chambre", "Johnny", new DateOnly(2021, 10, 10)), + new LessonEntity(4, "Le salon", "Clement", new DateOnly(2021, 10, 10))); + + modelBuilder.Entity().HasData( + new ParagraphEntity(1, "Le premier paragraphe", "Le contenu du premier paragraphe", "Attention", "La query", + "Le commentaire", 1), + new ParagraphEntity(2, "Le deuxième paragraphe", "Le contenu du deuxième paragraphe", "Attention", + "La query", "Le commentaire", 1), + new ParagraphEntity(3, "Le troisième paragraphe", "Le contenu du troisième paragraphe", "Attention", + "query", "commentaire", 2), + new ParagraphEntity(4, "Le quatrième paragraphe", "Le contenu du quatrième paragraphe", "Attention", + "La query", "Le commentaire", 3), + new ParagraphEntity(5, "Le cinquième paragraphe", "Le contenu du quatrième paragraphe", "Attention", + "La query", "Le commentaire", 4)); } } \ No newline at end of file