diff --git a/Sources/EntityFramework/LoLDbContext.cs b/Sources/EntityFramework/LoLDbContext.cs index 57d65a8..6812e57 100644 --- a/Sources/EntityFramework/LoLDbContext.cs +++ b/Sources/EntityFramework/LoLDbContext.cs @@ -80,6 +80,7 @@ namespace EntityFramework // Many to Many ChampionEntity - RunePageEntity + modelBuilder.Entity().HasKey(entity => entity.Name); modelBuilder.Entity().HasKey(entity => entity.Name); modelBuilder.Entity().ToTable("RunePage"); diff --git a/Sources/EntityFramework/Migrations/20230315145258_myMig.Designer.cs b/Sources/EntityFramework/Migrations/20230323203441_manymanymig.Designer.cs similarity index 65% rename from Sources/EntityFramework/Migrations/20230315145258_myMig.Designer.cs rename to Sources/EntityFramework/Migrations/20230323203441_manymanymig.Designer.cs index 34ce7d8..f36cc78 100644 --- a/Sources/EntityFramework/Migrations/20230315145258_myMig.Designer.cs +++ b/Sources/EntityFramework/Migrations/20230323203441_manymanymig.Designer.cs @@ -9,9 +9,9 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace EntityFramework.Migrations { - [DbContext(typeof(LoLDBContextWithStub))] - [Migration("20230315145258_myMig")] - partial class myMig + [DbContext(typeof(LoLDbContext))] + [Migration("20230323203441_manymanymig")] + partial class manymanymig { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -19,6 +19,21 @@ namespace EntityFramework.Migrations #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + modelBuilder.Entity("ChampionEntityRunePageEntity", b => + { + b.Property("ChampionName") + .HasColumnType("TEXT"); + + b.Property("RunePageEntitiesName") + .HasColumnType("TEXT"); + + b.HasKey("ChampionName", "RunePageEntitiesName"); + + b.HasIndex("RunePageEntitiesName"); + + b.ToTable("ChampionEntityRunePageEntity"); + }); + modelBuilder.Entity("EntityFramework.ChampionEntity", b => { b.Property("Name") @@ -41,44 +56,6 @@ namespace EntityFramework.Migrations b.HasKey("Name"); b.ToTable("Champion", (string)null); - - b.HasData( - new - { - Name = "Akali", - Bio = "", - Icon = "" - }, - new - { - Name = "Aatrox", - Bio = "", - Icon = "" - }, - new - { - Name = "Ahri", - Bio = "", - Icon = "" - }, - new - { - Name = "Akshan", - Bio = "", - Icon = "" - }, - new - { - Name = "Bard", - Bio = "", - Icon = "" - }, - new - { - Name = "Alistar", - Bio = "", - Icon = "" - }); }); modelBuilder.Entity("EntityFramework.LargeImageEntity", b => @@ -96,6 +73,31 @@ namespace EntityFramework.Migrations b.ToTable("Image"); }); + modelBuilder.Entity("EntityFramework.RuneEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("Rune"); + }); + + modelBuilder.Entity("EntityFramework.RunePageEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("RuneName") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.HasIndex("RuneName"); + + b.ToTable("RunePage", (string)null); + }); + modelBuilder.Entity("EntityFramework.SkillEntity", b => { b.Property("Name") @@ -147,6 +149,30 @@ namespace EntityFramework.Migrations b.ToTable("Skins"); }); + modelBuilder.Entity("ChampionEntityRunePageEntity", b => + { + b.HasOne("EntityFramework.ChampionEntity", null) + .WithMany() + .HasForeignKey("ChampionName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFramework.RunePageEntity", null) + .WithMany() + .HasForeignKey("RunePageEntitiesName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("EntityFramework.RunePageEntity", b => + { + b.HasOne("EntityFramework.RuneEntity", "Rune") + .WithMany() + .HasForeignKey("RuneName"); + + b.Navigation("Rune"); + }); + modelBuilder.Entity("EntityFramework.SkillEntity", b => { b.HasOne("EntityFramework.ChampionEntity", null) diff --git a/Sources/EntityFramework/Migrations/20230315145258_myMig.cs b/Sources/EntityFramework/Migrations/20230323203441_manymanymig.cs similarity index 58% rename from Sources/EntityFramework/Migrations/20230315145258_myMig.cs rename to Sources/EntityFramework/Migrations/20230323203441_manymanymig.cs index 86b3a87..3908652 100644 --- a/Sources/EntityFramework/Migrations/20230315145258_myMig.cs +++ b/Sources/EntityFramework/Migrations/20230323203441_manymanymig.cs @@ -2,12 +2,10 @@ #nullable disable -#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional - namespace EntityFramework.Migrations { /// - public partial class myMig : Migration + public partial class manymanymig : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -39,6 +37,17 @@ namespace EntityFramework.Migrations table.PrimaryKey("PK_Image", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Rune", + columns: table => new + { + Name = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Rune", x => x.Name); + }); + migrationBuilder.CreateTable( name: "SkillEntity", columns: table => new @@ -79,19 +88,57 @@ namespace EntityFramework.Migrations principalColumn: "Name"); }); - migrationBuilder.InsertData( - table: "Champion", - columns: new[] { "Name", "Bio", "Icon", "Image" }, - values: new object[,] + migrationBuilder.CreateTable( + name: "RunePage", + columns: table => new + { + Name = table.Column(type: "TEXT", nullable: false), + RuneName = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_RunePage", x => x.Name); + table.ForeignKey( + name: "FK_RunePage_Rune_RuneName", + column: x => x.RuneName, + principalTable: "Rune", + principalColumn: "Name"); + }); + + migrationBuilder.CreateTable( + name: "ChampionEntityRunePageEntity", + columns: table => new + { + ChampionName = table.Column(type: "TEXT", nullable: false), + RunePageEntitiesName = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => { - { "Aatrox", "", "", null }, - { "Ahri", "", "", null }, - { "Akali", "", "", null }, - { "Akshan", "", "", null }, - { "Alistar", "", "", null }, - { "Bard", "", "", null } + table.PrimaryKey("PK_ChampionEntityRunePageEntity", x => new { x.ChampionName, x.RunePageEntitiesName }); + table.ForeignKey( + name: "FK_ChampionEntityRunePageEntity_Champion_ChampionName", + column: x => x.ChampionName, + principalTable: "Champion", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ChampionEntityRunePageEntity_RunePage_RunePageEntitiesName", + column: x => x.RunePageEntitiesName, + principalTable: "RunePage", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateIndex( + name: "IX_ChampionEntityRunePageEntity_RunePageEntitiesName", + table: "ChampionEntityRunePageEntity", + column: "RunePageEntitiesName"); + + migrationBuilder.CreateIndex( + name: "IX_RunePage_RuneName", + table: "RunePage", + column: "RuneName"); + migrationBuilder.CreateIndex( name: "IX_SkillEntity_ChampionEntityName", table: "SkillEntity", @@ -106,6 +153,9 @@ namespace EntityFramework.Migrations /// protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropTable( + name: "ChampionEntityRunePageEntity"); + migrationBuilder.DropTable( name: "Image"); @@ -115,8 +165,14 @@ namespace EntityFramework.Migrations migrationBuilder.DropTable( name: "Skins"); + migrationBuilder.DropTable( + name: "RunePage"); + migrationBuilder.DropTable( name: "Champion"); + + migrationBuilder.DropTable( + name: "Rune"); } } } diff --git a/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs b/Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs similarity index 64% rename from Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs rename to Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs index 1bbd357..e65f6fe 100644 --- a/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs +++ b/Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs @@ -8,14 +8,29 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace EntityFramework.Migrations { - [DbContext(typeof(LoLDBContextWithStub))] - partial class LoLDBContextWithStubModelSnapshot : 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("ChampionName") + .HasColumnType("TEXT"); + + b.Property("RunePageEntitiesName") + .HasColumnType("TEXT"); + + b.HasKey("ChampionName", "RunePageEntitiesName"); + + b.HasIndex("RunePageEntitiesName"); + + b.ToTable("ChampionEntityRunePageEntity"); + }); + modelBuilder.Entity("EntityFramework.ChampionEntity", b => { b.Property("Name") @@ -38,44 +53,6 @@ namespace EntityFramework.Migrations b.HasKey("Name"); b.ToTable("Champion", (string)null); - - b.HasData( - new - { - Name = "Akali", - Bio = "", - Icon = "" - }, - new - { - Name = "Aatrox", - Bio = "", - Icon = "" - }, - new - { - Name = "Ahri", - Bio = "", - Icon = "" - }, - new - { - Name = "Akshan", - Bio = "", - Icon = "" - }, - new - { - Name = "Bard", - Bio = "", - Icon = "" - }, - new - { - Name = "Alistar", - Bio = "", - Icon = "" - }); }); modelBuilder.Entity("EntityFramework.LargeImageEntity", b => @@ -93,6 +70,31 @@ namespace EntityFramework.Migrations b.ToTable("Image"); }); + modelBuilder.Entity("EntityFramework.RuneEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("Rune"); + }); + + modelBuilder.Entity("EntityFramework.RunePageEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("RuneName") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.HasIndex("RuneName"); + + b.ToTable("RunePage", (string)null); + }); + modelBuilder.Entity("EntityFramework.SkillEntity", b => { b.Property("Name") @@ -144,6 +146,30 @@ namespace EntityFramework.Migrations b.ToTable("Skins"); }); + modelBuilder.Entity("ChampionEntityRunePageEntity", b => + { + b.HasOne("EntityFramework.ChampionEntity", null) + .WithMany() + .HasForeignKey("ChampionName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFramework.RunePageEntity", null) + .WithMany() + .HasForeignKey("RunePageEntitiesName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("EntityFramework.RunePageEntity", b => + { + b.HasOne("EntityFramework.RuneEntity", "Rune") + .WithMany() + .HasForeignKey("RuneName"); + + b.Navigation("Rune"); + }); + modelBuilder.Entity("EntityFramework.SkillEntity", b => { b.HasOne("EntityFramework.ChampionEntity", null) diff --git a/Sources/EntityFramework/Program.cs b/Sources/EntityFramework/Program.cs index 818faa5..dfe3c7e 100644 --- a/Sources/EntityFramework/Program.cs +++ b/Sources/EntityFramework/Program.cs @@ -1,6 +1,8 @@ // See https://aka.ms/new-console-template for more information using EntityFramework; using Microsoft.EntityFrameworkCore; +using Model; +using System.Buffers.Text; using ( var context = new LoLDbContext()) { @@ -24,10 +26,10 @@ using ( var context = new LoLDbContext()) ChampionEntity champSkill = new ChampionEntity { Name="nomSkill", Bio="bioSkill", Icon="iconSkill" }; //SkillEntity s1 = new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown }; - SkillEntity s2 = new SkillEntity { Name="Skill2", Description="desc2", Type=SkillType.Ultimate }; - SkillEntity s3 = new SkillEntity { Name = "Skill3", Description = "desc3", Type = SkillType.Passive }; + SkillEntity s2 = new SkillEntity { Name="Skill2", Description="desc2", Type= EntityFramework.SkillType.Ultimate }; + SkillEntity s3 = new SkillEntity { Name = "Skill3", Description = "desc3", Type = EntityFramework.SkillType.Passive }; - champSkill.AddSkill(new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown }); + champSkill.AddSkill(new SkillEntity { Name = "Skill1", Description = "desc", Type = EntityFramework.SkillType.Unknown }); champSkill.AddSkill(s2); champSkill.AddSkill(s3); @@ -75,4 +77,15 @@ using ( var context = new LoLDbContext()) context.SaveChanges(); + var r1 = new RuneEntity { Name = "Rune1", Description = "aaa", Family = EnumRuneFamily.Domination, Image = new LargeImage("base") }; + var r2 = new RuneEntity { Name = "Rune2", Description = "aaa", Family = EnumRuneFamily.Domination, Image = new LargeImage("base") }; + var corichard = new ChampionEntity { Name = "Corichard", Bio = "biobio", Icon = "Icon.png" }; + var pintrand = new ChampionEntity { Name = "Pintrand", Bio = "biobio", Icon = "Icon.png" }; + var rp1 = new RunePageEntity { Name = "RP1", Rune = new RuneEntity { Name = "aa", Description = "aaa", Family = EnumRuneFamily.Domination, Image = new LargeImage("base") }, Champion = new List { corichard } }; + var rp2 = new RunePageEntity { Name = "RP2", Rune = new RuneEntity{ Name = "aaa", Description = "aaa", Family = EnumRuneFamily.Domination, Image = new LargeImage("base") }, Champion = new List { pintrand } }; + + context.Rune.AddRange(new[] { r1, r2 }); + context.Champions.AddRange(new[] { corichard, pintrand }); + context.RunePage.AddRange(new[] { rp1, rp2 }); + context.SaveChanges(); } diff --git a/Sources/EntityFramework/RunePageEntity.cs b/Sources/EntityFramework/RunePageEntity.cs index 7e4e1ce..842806b 100644 --- a/Sources/EntityFramework/RunePageEntity.cs +++ b/Sources/EntityFramework/RunePageEntity.cs @@ -11,9 +11,9 @@ namespace EntityFramework public class RunePageEntity { [Key] - public int Name { get; set; } + public string Name { get; set; } - public Rune? Rune { get; set; } + public RuneEntity? Rune { get; set; } //? voir si cela pause probleme public Dictionary Dico = new Dictionary(); diff --git a/Sources/EntityFramework/champion.db b/Sources/EntityFramework/champion.db index d4cefaf..acdfad4 100644 Binary files a/Sources/EntityFramework/champion.db and b/Sources/EntityFramework/champion.db differ