diff --git a/EntityFramework_LoL/Sources/Business/DbData.Champions.cs b/EntityFramework_LoL/Sources/Business/DbData.Champions.cs index 03d2ff8..52bfe7f 100644 --- a/EntityFramework_LoL/Sources/Business/DbData.Champions.cs +++ b/EntityFramework_LoL/Sources/Business/DbData.Champions.cs @@ -55,7 +55,7 @@ namespace Business public async Task> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false) { - return parent.DbContext.champions.Where(c => c.runepages.Any(rp => rp.Equals(runePage.ToEntity()) + return parent.DbContext.champions.Where(c => c.runepages.Any(rp => rp.Equals(runePage.ToEntity()))) .Select(c => c.ToModel()) .Skip(index * count).Take(count); } diff --git a/EntityFramework_LoL/Sources/Entities/CharacteristicEntity.cs b/EntityFramework_LoL/Sources/Entities/CharacteristicEntity.cs index 8ad635c..e780845 100644 --- a/EntityFramework_LoL/Sources/Entities/CharacteristicEntity.cs +++ b/EntityFramework_LoL/Sources/Entities/CharacteristicEntity.cs @@ -20,8 +20,6 @@ namespace Entities [Required] public string ChampionForeignKey { get; set; } - [Key] - [Required] [ForeignKey("ChampionForeignKey")] public ChampionEntity Champion { get; set; } } diff --git a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-shm b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-shm index 559b34c..927dd66 100644 Binary files a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-shm and b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-shm differ diff --git a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-wal b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-wal index d2719b5..50a0bc3 100644 Binary files a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-wal and b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-wal differ diff --git a/EntityFramework_LoL/Sources/Entities/LolDbContext.cs b/EntityFramework_LoL/Sources/Entities/LolDbContext.cs index 52b49a5..52795fd 100644 --- a/EntityFramework_LoL/Sources/Entities/LolDbContext.cs +++ b/EntityFramework_LoL/Sources/Entities/LolDbContext.cs @@ -26,6 +26,7 @@ namespace Entities { modelBuilder.Entity().Property(e => e.Id).ValueGeneratedOnAdd(); + modelBuilder.Entity().HasKey(c => new { c.Name, c.ChampionForeignKey }); modelBuilder.Entity().Property(e => e.Id).ValueGeneratedOnAdd(); modelBuilder.Entity() @@ -33,6 +34,12 @@ namespace Entities .WithMany(x => x.runepages) .UsingEntity(); + modelBuilder.Entity() + .HasMany(x => x.runepages) + .WithMany(x => x.champions); + + + modelBuilder.Entity().HasData(new List() { diff --git a/EntityFramework_LoL/Sources/Entities/Migrations/20230209133904_myFirstMigration.Designer.cs b/EntityFramework_LoL/Sources/Entities/Migrations/20230301162639_myFirstMigration.Designer.cs similarity index 77% rename from EntityFramework_LoL/Sources/Entities/Migrations/20230209133904_myFirstMigration.Designer.cs rename to EntityFramework_LoL/Sources/Entities/Migrations/20230301162639_myFirstMigration.Designer.cs index 81f4297..e62e66e 100644 --- a/EntityFramework_LoL/Sources/Entities/Migrations/20230209133904_myFirstMigration.Designer.cs +++ b/EntityFramework_LoL/Sources/Entities/Migrations/20230301162639_myFirstMigration.Designer.cs @@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace Entities.Migrations { - [DbContext(typeof(ChampionDbContext))] - [Migration("20230209133904_myFirstMigration")] + [DbContext(typeof(LolDbContext))] + [Migration("20230301162639_myFirstMigration")] partial class myFirstMigration { /// @@ -20,6 +20,21 @@ namespace Entities.Migrations #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + modelBuilder.Entity("ChampionEntityRunePageEntity", b => + { + b.Property("championsName") + .HasColumnType("TEXT"); + + b.Property("runepagesId") + .HasColumnType("TEXT"); + + b.HasKey("championsName", "runepagesId"); + + b.HasIndex("runepagesId"); + + b.ToTable("ChampionEntityRunePageEntity"); + }); + modelBuilder.Entity("ChampionEntitySkillEntity", b => { b.Property("ChampionsName") @@ -76,6 +91,39 @@ namespace Entities.Migrations }); }); + modelBuilder.Entity("Entities.CharacteristicEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("ChampionForeignKey") + .HasColumnType("TEXT"); + + b.Property("Value") + .HasColumnType("INTEGER"); + + b.HasKey("Name", "ChampionForeignKey"); + + b.HasIndex("ChampionForeignKey"); + + b.ToTable("characteristics"); + + b.HasData( + new + { + Name = "Force", + ChampionForeignKey = "Dave", + Value = 50 + }, + new + { + Name = "Défense", + ChampionForeignKey = "Armure", + Value = 75 + }); + }); + modelBuilder.Entity("Entities.LargeImageEntity", b => { b.Property("Id") @@ -93,7 +141,7 @@ namespace Entities.Migrations b.HasData( new { - Id = new Guid("70d7aace-13a9-40e1-bd94-99790805f6d0"), + Id = new Guid("d3a490c6-fb49-475a-9134-47c2de9888d2"), Base64 = "aaa" }); }); @@ -154,7 +202,7 @@ namespace Entities.Migrations b.HasData( new { - Id = new Guid("a5a4f69b-5cbb-48c1-beb4-896bc9171714"), + Id = new Guid("4ea04d4f-0a64-4d28-8d74-4499dbc541f2"), Name = "Runepage_1" }); }); @@ -262,6 +310,21 @@ namespace Entities.Migrations }); }); + modelBuilder.Entity("ChampionEntityRunePageEntity", b => + { + b.HasOne("Entities.ChampionEntity", null) + .WithMany() + .HasForeignKey("championsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entities.RunePageEntity", null) + .WithMany() + .HasForeignKey("runepagesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("ChampionEntitySkillEntity", b => { b.HasOne("Entities.ChampionEntity", null) @@ -286,6 +349,17 @@ namespace Entities.Migrations b.Navigation("Image"); }); + modelBuilder.Entity("Entities.CharacteristicEntity", b => + { + b.HasOne("Entities.ChampionEntity", "Champion") + .WithMany("Characteristics") + .HasForeignKey("ChampionForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Champion"); + }); + modelBuilder.Entity("Entities.RuneEntity", b => { b.HasOne("Entities.LargeImageEntity", "Image") @@ -326,6 +400,11 @@ namespace Entities.Migrations b.Navigation("Image"); }); + + modelBuilder.Entity("Entities.ChampionEntity", b => + { + b.Navigation("Characteristics"); + }); #pragma warning restore 612, 618 } } diff --git a/EntityFramework_LoL/Sources/Entities/Migrations/20230209133904_myFirstMigration.cs b/EntityFramework_LoL/Sources/Entities/Migrations/20230301162639_myFirstMigration.cs similarity index 77% rename from EntityFramework_LoL/Sources/Entities/Migrations/20230209133904_myFirstMigration.cs rename to EntityFramework_LoL/Sources/Entities/Migrations/20230301162639_myFirstMigration.cs index eb3748a..e3dd73d 100644 --- a/EntityFramework_LoL/Sources/Entities/Migrations/20230209133904_myFirstMigration.cs +++ b/EntityFramework_LoL/Sources/Entities/Migrations/20230301162639_myFirstMigration.cs @@ -89,6 +89,30 @@ namespace Entities.Migrations principalColumn: "Id"); }); + migrationBuilder.CreateTable( + name: "ChampionEntityRunePageEntity", + columns: table => new + { + championsName = table.Column(type: "TEXT", nullable: false), + runepagesId = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ChampionEntityRunePageEntity", x => new { x.championsName, x.runepagesId }); + table.ForeignKey( + name: "FK_ChampionEntityRunePageEntity_champions_championsName", + column: x => x.championsName, + principalTable: "champions", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ChampionEntityRunePageEntity_runepages_runepagesId", + column: x => x.runepagesId, + principalTable: "runepages", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "ChampionEntitySkillEntity", columns: table => new @@ -113,6 +137,25 @@ namespace Entities.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "characteristics", + columns: table => new + { + Name = table.Column(type: "TEXT", maxLength: 256, nullable: false), + ChampionForeignKey = table.Column(type: "TEXT", nullable: false), + Value = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_characteristics", x => new { x.Name, x.ChampionForeignKey }); + table.ForeignKey( + name: "FK_characteristics_champions_ChampionForeignKey", + column: x => x.ChampionForeignKey, + principalTable: "champions", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "skins", columns: table => new @@ -177,12 +220,12 @@ namespace Entities.Migrations migrationBuilder.InsertData( table: "largeimages", columns: new[] { "Id", "Base64" }, - values: new object[] { new Guid("70d7aace-13a9-40e1-bd94-99790805f6d0"), "aaa" }); + values: new object[] { new Guid("d3a490c6-fb49-475a-9134-47c2de9888d2"), "aaa" }); migrationBuilder.InsertData( table: "runepages", columns: new[] { "Id", "Name" }, - values: new object[] { new Guid("a5a4f69b-5cbb-48c1-beb4-896bc9171714"), "Runepage_1" }); + values: new object[] { new Guid("4ea04d4f-0a64-4d28-8d74-4499dbc541f2"), "Runepage_1" }); migrationBuilder.InsertData( table: "runes", @@ -202,6 +245,15 @@ namespace Entities.Migrations { "White Star", "Random damage", 3 } }); + migrationBuilder.InsertData( + table: "characteristics", + columns: new[] { "ChampionForeignKey", "Name", "Value" }, + values: new object[,] + { + { "Armure", "Défense", 75 }, + { "Dave", "Force", 50 } + }); + migrationBuilder.InsertData( table: "skins", columns: new[] { "Name", "ChampionForeignKey", "Description", "Icon", "ImageId", "Price" }, @@ -211,6 +263,11 @@ namespace Entities.Migrations { "Dave de glace", "Dave", "Enneigé", "aaa", null, 7.99f } }); + migrationBuilder.CreateIndex( + name: "IX_ChampionEntityRunePageEntity_runepagesId", + table: "ChampionEntityRunePageEntity", + column: "runepagesId"); + migrationBuilder.CreateIndex( name: "IX_ChampionEntitySkillEntity_SkillsName", table: "ChampionEntitySkillEntity", @@ -221,6 +278,11 @@ namespace Entities.Migrations table: "champions", column: "ImageId"); + migrationBuilder.CreateIndex( + name: "IX_characteristics_ChampionForeignKey", + table: "characteristics", + column: "ChampionForeignKey"); + migrationBuilder.CreateIndex( name: "IX_RunePageRuneEntity_runesName", table: "RunePageRuneEntity", @@ -245,9 +307,15 @@ namespace Entities.Migrations /// protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropTable( + name: "ChampionEntityRunePageEntity"); + migrationBuilder.DropTable( name: "ChampionEntitySkillEntity"); + migrationBuilder.DropTable( + name: "characteristics"); + migrationBuilder.DropTable( name: "RunePageRuneEntity"); diff --git a/EntityFramework_LoL/Sources/Entities/Migrations/ChampionDbContextModelSnapshot.cs b/EntityFramework_LoL/Sources/Entities/Migrations/LolDbContextModelSnapshot.cs similarity index 77% rename from EntityFramework_LoL/Sources/Entities/Migrations/ChampionDbContextModelSnapshot.cs rename to EntityFramework_LoL/Sources/Entities/Migrations/LolDbContextModelSnapshot.cs index aef1440..e343e94 100644 --- a/EntityFramework_LoL/Sources/Entities/Migrations/ChampionDbContextModelSnapshot.cs +++ b/EntityFramework_LoL/Sources/Entities/Migrations/LolDbContextModelSnapshot.cs @@ -9,14 +9,29 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace Entities.Migrations { - [DbContext(typeof(ChampionDbContext))] - partial class ChampionDbContextModelSnapshot : ModelSnapshot + [DbContext(typeof(LolDbContext))] + partial class LolDbContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + modelBuilder.Entity("ChampionEntityRunePageEntity", b => + { + b.Property("championsName") + .HasColumnType("TEXT"); + + b.Property("runepagesId") + .HasColumnType("TEXT"); + + b.HasKey("championsName", "runepagesId"); + + b.HasIndex("runepagesId"); + + b.ToTable("ChampionEntityRunePageEntity"); + }); + modelBuilder.Entity("ChampionEntitySkillEntity", b => { b.Property("ChampionsName") @@ -73,6 +88,39 @@ namespace Entities.Migrations }); }); + modelBuilder.Entity("Entities.CharacteristicEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("ChampionForeignKey") + .HasColumnType("TEXT"); + + b.Property("Value") + .HasColumnType("INTEGER"); + + b.HasKey("Name", "ChampionForeignKey"); + + b.HasIndex("ChampionForeignKey"); + + b.ToTable("characteristics"); + + b.HasData( + new + { + Name = "Force", + ChampionForeignKey = "Dave", + Value = 50 + }, + new + { + Name = "Défense", + ChampionForeignKey = "Armure", + Value = 75 + }); + }); + modelBuilder.Entity("Entities.LargeImageEntity", b => { b.Property("Id") @@ -90,7 +138,7 @@ namespace Entities.Migrations b.HasData( new { - Id = new Guid("70d7aace-13a9-40e1-bd94-99790805f6d0"), + Id = new Guid("d3a490c6-fb49-475a-9134-47c2de9888d2"), Base64 = "aaa" }); }); @@ -151,7 +199,7 @@ namespace Entities.Migrations b.HasData( new { - Id = new Guid("a5a4f69b-5cbb-48c1-beb4-896bc9171714"), + Id = new Guid("4ea04d4f-0a64-4d28-8d74-4499dbc541f2"), Name = "Runepage_1" }); }); @@ -259,6 +307,21 @@ namespace Entities.Migrations }); }); + modelBuilder.Entity("ChampionEntityRunePageEntity", b => + { + b.HasOne("Entities.ChampionEntity", null) + .WithMany() + .HasForeignKey("championsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entities.RunePageEntity", null) + .WithMany() + .HasForeignKey("runepagesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("ChampionEntitySkillEntity", b => { b.HasOne("Entities.ChampionEntity", null) @@ -283,6 +346,17 @@ namespace Entities.Migrations b.Navigation("Image"); }); + modelBuilder.Entity("Entities.CharacteristicEntity", b => + { + b.HasOne("Entities.ChampionEntity", "Champion") + .WithMany("Characteristics") + .HasForeignKey("ChampionForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Champion"); + }); + modelBuilder.Entity("Entities.RuneEntity", b => { b.HasOne("Entities.LargeImageEntity", "Image") @@ -323,6 +397,11 @@ namespace Entities.Migrations b.Navigation("Image"); }); + + modelBuilder.Entity("Entities.ChampionEntity", b => + { + b.Navigation("Characteristics"); + }); #pragma warning restore 612, 618 } }