From 21a5cfdbeb4a58d632c0467215851dcf437f99bd Mon Sep 17 00:00:00 2001 From: Louis DUFOUR Date: Wed, 22 Mar 2023 19:52:44 +0100 Subject: [PATCH] =?UTF-8?q?EF=20marche=20enfin=20(m=C3=AAme=20si=20le=20re?= =?UTF-8?q?sutlat=20semble=20bizzare)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/EFMapping/EFChampionMapper.cs | 9 ++-- Sources/EFMapping/EFCharacteristicsMapper.cs | 10 +--- Sources/EFMapping/EFSkillMapper.cs | 6 ++- Sources/EFlib/EFChampion.cs | 4 +- Sources/EFlib/EFSkill.cs | 7 +++ ...=> 20230322184745_myMigration.Designer.cs} | 48 ++++++++++++------ ...ation.cs => 20230322184745_myMigration.cs} | 47 ++++++++++++----- .../Migrations/SQLiteContextModelSnapshot.cs | 46 ++++++++++++----- Sources/EFlib/projet.dbloulou.db | Bin 73728 -> 81920 bytes 9 files changed, 120 insertions(+), 57 deletions(-) rename Sources/EFlib/Migrations/{20230322115837_myMigration.Designer.cs => 20230322184745_myMigration.Designer.cs} (85%) rename Sources/EFlib/Migrations/{20230322115837_myMigration.cs => 20230322184745_myMigration.cs} (80%) 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 743b2966fe010ba651d1754b72dbc11dc91652e4..3b71c7873a0b772a04394d827b388d8aef28212e 100644 GIT binary patch delta 872 zcmZoTz|zpbIzgUSgaH9~ChFK|2{Usu@Ll3x%lngWHm@Y_8SZkPXPlS0E!cZGC$Pq{ zC$W5HNn}3DT*Az~abhJCQ@Zfvdn{^+3VN>z5=Zb zqPh#_EM6`JAW(vZ2sjWXKV%o@LO2)56`MSPo5wN08#C;b6as=geI0`$6}(*|fxbjB zNJ&Ql#oLqlxWwErTp177gJ6N;LP^2RKgiY7-4C15lM^|-0x^w(xEd)!(G5X(OG#59 z$koj?$kor;H5ls7$v?Oi*c^G-#6$H#!LEU6fgy$vZ&MQIS6StQH>EVTX&k#&+{?7YZkk!J(+{AS8dwBr}Yx5UBiwQpf delta 510 zcmZo@U~M?SGC`hKhyek(C+gU!39{T_;Jd`XmiH&$Y@Tr5V_chgBsguk+SqwHh1eFe z39`;(b!EA;Sx~@_g(+QdGB2|lqtIj%W=BSW$z{w6jDnM=Gn>^H^0SNEN-{P|X6B`& zR(M9l2WMyIVUEEunvC%X$Z*ne+AtV3f`7EJ~ypzAOXfpCmmS=Tfwk<{#wh>F%fC?HY;V{K*$N)L41BG_|=VpX1eH;ciM| zpL~r|i;-h9BbNmuD+il+pf=c@VcZHVoJ~2bldHJp7}++@xG(^A~-d1&bU6kP!fZ9*%DS