testConsoleEF #38

Merged
johnny.ratton merged 3 commits from testConsoleEF into master 1 year ago

@ -12,7 +12,6 @@ namespace DbContextLib
public DbSet<InquiryEntity> Inquiries { get; set; }
public DbSet<InquiryTableEntity> InquiryTables { get; set; }
public DbSet<LessonEntity> Lessons { get; set; }
public DbSet<ContentLessonEntity> ContentLessons { get; set; }
public DbSet<ParagraphEntity> Paragraphs { get; set; }
public DbSet<SolutionEntity> Solutions { get; set; }
public DbSet<SuccessEntity> Successes { get; set; }
@ -34,7 +33,9 @@ namespace DbContextLib
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ContentLessonEntity>().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<ContentLessonEntity>().UseTpcMappingStrategy();
modelBuilder.Entity<SuccessEntity>().HasKey(s => s.UserId);
modelBuilder.Entity<SuccessEntity>().HasKey(s => s.InquiryId);
modelBuilder.Entity<InquiryEntity>().HasKey(s => s.Id);

@ -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()
{

@ -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;
@ -58,9 +57,26 @@ public class StubbedContext : UserDbContext
modelBuilder.Entity<SolutionEntity>().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<LessonEntity>().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<ParagraphEntity>().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));
modelBuilder.Entity<InquiryEntity>().HasData(
new InquiryEntity(1, "L'enquête de la carotte", "La description de l'inquiry1", true),
new InquiryEntity(2, "L'enquête sur les orang outan", "The new description", false),

Loading…
Cancel
Save