diff --git a/Sources/EFMapping/EFChampionMapper.cs b/Sources/EFMapping/EFChampionMapper.cs index 4053663..beb6d02 100644 --- a/Sources/EFMapping/EFChampionMapper.cs +++ b/Sources/EFMapping/EFChampionMapper.cs @@ -1,5 +1,7 @@ using EFlib; using Model; +using System.Collections.Immutable; +using System.Reflection.PortableExecutable; namespace EFMapping { @@ -19,10 +21,11 @@ namespace EFMapping Icon = Champ.Icon, Class = Champ.Class, Image = new() { Id = Guid.NewGuid(), Base64 = Champ.Image.Base64 }, - Skills = Champ.Skills.Select(Skill => Skill.toEF(EfChampion, context)).ToList(), - Characteristics = Champ.Characteristics.Select(Charac => Charac.toEF(EfChampion, context)).ToList() - }; + + }; + EfChampion.Skills = Champ.Skills.Select(skill => skill.toEF(EfChampion, context)).ToList(); + EfChampion.Characteristics = Champ.Characteristics.Select(Charac => Charac.toEF(EfChampion, context)).ToList(); } return EfChampion; diff --git a/Sources/EFMapping/EFCharacteristicsMapper.cs b/Sources/EFMapping/EFCharacteristicsMapper.cs index 306a968..779d95e 100644 --- a/Sources/EFMapping/EFCharacteristicsMapper.cs +++ b/Sources/EFMapping/EFCharacteristicsMapper.cs @@ -26,13 +26,7 @@ namespace EFMapping return EfCharacteristics; } - public static ReadOnlyDictionary toModel(this EFCharacteristics charac) - { - var dict = new Dictionary - { - { charac.Name, charac.Value } - }; - return new(dict); - } + public static Tuple toModel(this EFCharacteristics Charac)=> new(Charac.Name, Charac.Value); + } } diff --git a/Sources/EFMapping/EFSkillMapper.cs b/Sources/EFMapping/EFSkillMapper.cs index 292c717..1a615dc 100644 --- a/Sources/EFMapping/EFSkillMapper.cs +++ b/Sources/EFMapping/EFSkillMapper.cs @@ -10,7 +10,7 @@ namespace EFMapping { public static class EFSkillMapper { - public static EFSkill toEF(this Skill skill, SQLiteContext context) + public static EFSkill toEF(this Skill skill, EFChampion champ, SQLiteContext context) { var EfSkill = context.Skills.Find(skill.Name); if (EfSkill == null) @@ -19,9 +19,11 @@ namespace EFMapping { Name = skill.Name, Description = skill.Description, - Type = skill.Type + Type = skill.Type, + Champions = new List() { champ } }; } + EfSkill!.Champions?.Add(champ); return EfSkill; } public static Skill toModel(this EFSkill skill)=> new(skill.Name, skill.Type, skill.Description); diff --git a/Sources/EFlib/EFChampion.cs b/Sources/EFlib/EFChampion.cs index 90b8317..97a9b2a 100644 --- a/Sources/EFlib/EFChampion.cs +++ b/Sources/EFlib/EFChampion.cs @@ -20,12 +20,12 @@ namespace EFlib public string Icon { get; set; } // Propriété de navigation pour les paires clé-valeur - public ICollection Characteristics { get; set; } + public virtual ICollection Characteristics { get; set; } [Required] public ChampionClass Class { get; set; } public ReadOnlyCollection? Skins { get; set; } - public ImmutableHashSet Skills { get; set; } + public virtual ICollection Skills { get; set; } public Guid ImageId { get; set; } [ForeignKey("ImageId")] diff --git a/Sources/EFlib/EFSkill.cs b/Sources/EFlib/EFSkill.cs index 16825bc..7d68e6e 100644 --- a/Sources/EFlib/EFSkill.cs +++ b/Sources/EFlib/EFSkill.cs @@ -12,8 +12,15 @@ namespace EFlib public class EFSkill { [Key] + [MaxLength(250)] public string Name { get; set; } + + [Required] + [MaxLength(500)] public string Description { get; set; } + [Required] public SkillType Type { get; set; } + + public virtual ICollection? Champions { get; set; } } } diff --git a/Sources/EFlib/Migrations/20230322115837_myMigration.Designer.cs b/Sources/EFlib/Migrations/20230322184745_myMigration.Designer.cs similarity index 85% rename from Sources/EFlib/Migrations/20230322115837_myMigration.Designer.cs rename to Sources/EFlib/Migrations/20230322184745_myMigration.Designer.cs index 8d749e0..4dbae5d 100644 --- a/Sources/EFlib/Migrations/20230322115837_myMigration.Designer.cs +++ b/Sources/EFlib/Migrations/20230322184745_myMigration.Designer.cs @@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace EFlib.Migrations { [DbContext(typeof(SQLiteContext))] - [Migration("20230322115837_myMigration")] + [Migration("20230322184745_myMigration")] partial class myMigration { /// @@ -20,6 +20,21 @@ namespace EFlib.Migrations #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + modelBuilder.Entity("EFChampionEFSkill", b => + { + b.Property("ChampionsName") + .HasColumnType("TEXT"); + + b.Property("SkillsName") + .HasColumnType("TEXT"); + + b.HasKey("ChampionsName", "SkillsName"); + + b.HasIndex("SkillsName"); + + b.ToTable("EFChampionEFSkill"); + }); + modelBuilder.Entity("EFlib.EFChampion", b => { b.Property("Name") @@ -86,13 +101,12 @@ namespace EFlib.Migrations modelBuilder.Entity("EFlib.EFSkill", b => { b.Property("Name") + .HasMaxLength(250) .HasColumnType("TEXT"); b.Property("Description") .IsRequired() - .HasColumnType("TEXT"); - - b.Property("EFChampionName") + .HasMaxLength(500) .HasColumnType("TEXT"); b.Property("Type") @@ -100,8 +114,6 @@ namespace EFlib.Migrations b.HasKey("Name"); - b.HasIndex("EFChampionName"); - b.ToTable("Skills"); }); @@ -137,6 +149,21 @@ namespace EFlib.Migrations b.ToTable("Skins"); }); + modelBuilder.Entity("EFChampionEFSkill", b => + { + b.HasOne("EFlib.EFChampion", null) + .WithMany() + .HasForeignKey("ChampionsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EFlib.EFSkill", null) + .WithMany() + .HasForeignKey("SkillsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("EFlib.EFChampion", b => { b.HasOne("EFlib.EFLargeImage", "Image") @@ -159,13 +186,6 @@ namespace EFlib.Migrations b.Navigation("Champion"); }); - modelBuilder.Entity("EFlib.EFSkill", b => - { - b.HasOne("EFlib.EFChampion", null) - .WithMany("Skills") - .HasForeignKey("EFChampionName"); - }); - modelBuilder.Entity("EFlib.EFSkin", b => { b.HasOne("EFlib.EFLargeImage", "Image") @@ -189,8 +209,6 @@ namespace EFlib.Migrations { b.Navigation("Characteristics"); - b.Navigation("Skills"); - b.Navigation("Skins"); }); #pragma warning restore 612, 618 diff --git a/Sources/EFlib/Migrations/20230322115837_myMigration.cs b/Sources/EFlib/Migrations/20230322184745_myMigration.cs similarity index 80% rename from Sources/EFlib/Migrations/20230322115837_myMigration.cs rename to Sources/EFlib/Migrations/20230322184745_myMigration.cs index bbc31f9..be12fa3 100644 --- a/Sources/EFlib/Migrations/20230322115837_myMigration.cs +++ b/Sources/EFlib/Migrations/20230322184745_myMigration.cs @@ -23,6 +23,19 @@ namespace EFlib.Migrations table.PrimaryKey("PK_LargeImages", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Skills", + columns: table => new + { + Name = table.Column(type: "TEXT", maxLength: 250, nullable: false), + Description = table.Column(type: "TEXT", maxLength: 500, nullable: false), + Type = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Skills", x => x.Name); + }); + migrationBuilder.CreateTable( name: "Champions", columns: table => new @@ -64,22 +77,27 @@ namespace EFlib.Migrations }); migrationBuilder.CreateTable( - name: "Skills", + name: "EFChampionEFSkill", columns: table => new { - Name = table.Column(type: "TEXT", nullable: false), - Description = table.Column(type: "TEXT", nullable: false), - Type = table.Column(type: "INTEGER", nullable: false), - EFChampionName = table.Column(type: "TEXT", nullable: true) + ChampionsName = table.Column(type: "TEXT", nullable: false), + SkillsName = table.Column(type: "TEXT", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_Skills", x => x.Name); + table.PrimaryKey("PK_EFChampionEFSkill", x => new { x.ChampionsName, x.SkillsName }); table.ForeignKey( - name: "FK_Skills_Champions_EFChampionName", - column: x => x.EFChampionName, + name: "FK_EFChampionEFSkill_Champions_ChampionsName", + column: x => x.ChampionsName, principalTable: "Champions", - principalColumn: "Name"); + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_EFChampionEFSkill_Skills_SkillsName", + column: x => x.SkillsName, + principalTable: "Skills", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( @@ -121,9 +139,9 @@ namespace EFlib.Migrations column: "NameChampion"); migrationBuilder.CreateIndex( - name: "IX_Skills_EFChampionName", - table: "Skills", - column: "EFChampionName"); + name: "IX_EFChampionEFSkill_SkillsName", + table: "EFChampionEFSkill", + column: "SkillsName"); migrationBuilder.CreateIndex( name: "IX_Skins_ImageId", @@ -143,11 +161,14 @@ namespace EFlib.Migrations name: "Characteristics"); migrationBuilder.DropTable( - name: "Skills"); + name: "EFChampionEFSkill"); migrationBuilder.DropTable( name: "Skins"); + migrationBuilder.DropTable( + name: "Skills"); + migrationBuilder.DropTable( name: "Champions"); diff --git a/Sources/EFlib/Migrations/SQLiteContextModelSnapshot.cs b/Sources/EFlib/Migrations/SQLiteContextModelSnapshot.cs index 1e48e5f..4fed84a 100644 --- a/Sources/EFlib/Migrations/SQLiteContextModelSnapshot.cs +++ b/Sources/EFlib/Migrations/SQLiteContextModelSnapshot.cs @@ -17,6 +17,21 @@ namespace EFlib.Migrations #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + modelBuilder.Entity("EFChampionEFSkill", b => + { + b.Property("ChampionsName") + .HasColumnType("TEXT"); + + b.Property("SkillsName") + .HasColumnType("TEXT"); + + b.HasKey("ChampionsName", "SkillsName"); + + b.HasIndex("SkillsName"); + + b.ToTable("EFChampionEFSkill"); + }); + modelBuilder.Entity("EFlib.EFChampion", b => { b.Property("Name") @@ -83,13 +98,12 @@ namespace EFlib.Migrations modelBuilder.Entity("EFlib.EFSkill", b => { b.Property("Name") + .HasMaxLength(250) .HasColumnType("TEXT"); b.Property("Description") .IsRequired() - .HasColumnType("TEXT"); - - b.Property("EFChampionName") + .HasMaxLength(500) .HasColumnType("TEXT"); b.Property("Type") @@ -97,8 +111,6 @@ namespace EFlib.Migrations b.HasKey("Name"); - b.HasIndex("EFChampionName"); - b.ToTable("Skills"); }); @@ -134,6 +146,21 @@ namespace EFlib.Migrations b.ToTable("Skins"); }); + modelBuilder.Entity("EFChampionEFSkill", b => + { + b.HasOne("EFlib.EFChampion", null) + .WithMany() + .HasForeignKey("ChampionsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EFlib.EFSkill", null) + .WithMany() + .HasForeignKey("SkillsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("EFlib.EFChampion", b => { b.HasOne("EFlib.EFLargeImage", "Image") @@ -156,13 +183,6 @@ namespace EFlib.Migrations b.Navigation("Champion"); }); - modelBuilder.Entity("EFlib.EFSkill", b => - { - b.HasOne("EFlib.EFChampion", null) - .WithMany("Skills") - .HasForeignKey("EFChampionName"); - }); - modelBuilder.Entity("EFlib.EFSkin", b => { b.HasOne("EFlib.EFLargeImage", "Image") @@ -186,8 +206,6 @@ namespace EFlib.Migrations { b.Navigation("Characteristics"); - b.Navigation("Skills"); - b.Navigation("Skins"); }); #pragma warning restore 612, 618 diff --git a/Sources/EFlib/projet.dbloulou.db b/Sources/EFlib/projet.dbloulou.db index 743b296..3b71c78 100644 Binary files a/Sources/EFlib/projet.dbloulou.db and b/Sources/EFlib/projet.dbloulou.db differ