diff --git a/Sources/EntityFramework/LoLDbContext.cs b/Sources/EntityFramework/LoLDbContext.cs index 042b646..8dbfbb0 100644 --- a/Sources/EntityFramework/LoLDbContext.cs +++ b/Sources/EntityFramework/LoLDbContext.cs @@ -13,8 +13,9 @@ namespace EntityFramework public DbSet Skins { get; set; } - public DbSet Image { get; set; } + public DbSet Skills { get; set; } + public DbSet Image { get; set; } public DbSet Rune { get; set; } @@ -46,7 +47,8 @@ namespace EntityFramework modelBuilder.Entity().Property(entity => entity.Name) .IsRequired() - .HasMaxLength(50); + .HasMaxLength(50) + .ValueGeneratedOnAdd(); modelBuilder.Entity().Property(entity => entity.Bio) .HasMaxLength(500) @@ -76,11 +78,32 @@ namespace EntityFramework .HasForeignKey("ChampionEntityForeignKey"); + /// One to many + /// ChampionEntity ---> * SkillEntity + //création de la table ChampionEntity + //modelBuilder.Entity().HasKey(c => c.Name); //définition de la clé primaire + //modelBuilder.Entity().Property(c => c.Name) + // .ValueGeneratedOnAdd(); //définition du mode de génération de la clé : génération à l'insertion + + //création de la table SkillEntity + modelBuilder.Entity().HasKey(s => s.Name); //définition de la clé primaire + modelBuilder.Entity().Property(s => s.Name) + .ValueGeneratedOnAdd(); //définition du mode de génération de la clé : génération à l'insertion + // Add the shadow property to the model + modelBuilder.Entity() + .Property("ChampionEntityToSkillForeignKey"); + + // Use the shadow property as a foreign key + modelBuilder.Entity() + .HasOne(s => s.Champion) + .WithMany(c => c.Skills) + .HasForeignKey("ChampionEntityToSkillForeignKey"); - // Many to Many ChampionEntity - RunePageEntity - modelBuilder.Entity().HasKey(entity => entity.Name); + + /// Many to Many ChampionEntity - RunePageEntity + modelBuilder.Entity().HasKey(entity => entity.Name); modelBuilder.Entity().HasKey(entity => entity.Name); modelBuilder.Entity().ToTable("RunePage"); @@ -95,6 +118,23 @@ namespace EntityFramework .HasMany(c => c.RunePageEntities) .WithMany(r => r.Champion); //.HasForeignKey("AlbumForeignKey"); + + + + //création de la table RuneEntity + modelBuilder.Entity().HasKey(r => r.Name); //définition de la clé primaire + modelBuilder.Entity().Property(r => r.Name) + .ValueGeneratedOnAdd(); //définition du mode de génération de la clé : génération à l'insertion + + modelBuilder.Entity() + .Property("RuneForeignKey"); + + modelBuilder.Entity() + .HasOne(r => r.RunePage) + .WithMany(rp => rp.Runes) + .HasForeignKey("RuneForeignKey"); + + } } } diff --git a/Sources/EntityFramework/Migrations/20230325150121_MigrSkill.Designer.cs b/Sources/EntityFramework/Migrations/20230325150121_MigrSkill.Designer.cs new file mode 100644 index 0000000..79aa753 --- /dev/null +++ b/Sources/EntityFramework/Migrations/20230325150121_MigrSkill.Designer.cs @@ -0,0 +1,225 @@ +// +using EntityFramework; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EntityFramework.Migrations +{ + [DbContext(typeof(LoLDbContext))] + [Migration("20230325150121_MigrSkill")] + partial class MigrSkill + { + /// + protected override void BuildTargetModel(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") + .ValueGeneratedOnAdd() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Bio") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("string") + .HasColumnName("Bio"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Image") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("Champions", (string)null); + }); + + modelBuilder.Entity("EntityFramework.LargeImageEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Base64") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Image"); + }); + + modelBuilder.Entity("EntityFramework.RuneEntity", b => + { + b.Property("Name") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("RuneForeignKey") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.HasIndex("RuneForeignKey"); + + 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") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("ChampionEntityToSkillForeignKey") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.HasIndex("ChampionEntityToSkillForeignKey"); + + b.ToTable("Skills"); + }); + + modelBuilder.Entity("EntityFramework.SkinEntity", b => + { + b.Property("Name") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("ChampionEntityForeignKey") + .HasColumnType("TEXT"); + + b.Property("Description") + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Image") + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Name"); + + b.HasIndex("ChampionEntityForeignKey"); + + 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.RuneEntity", b => + { + b.HasOne("EntityFramework.RunePageEntity", "RunePage") + .WithMany("Runes") + .HasForeignKey("RuneForeignKey"); + + b.Navigation("RunePage"); + }); + + 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", "Champion") + .WithMany("Skills") + .HasForeignKey("ChampionEntityToSkillForeignKey"); + + b.Navigation("Champion"); + }); + + modelBuilder.Entity("EntityFramework.SkinEntity", b => + { + b.HasOne("EntityFramework.ChampionEntity", "Champion") + .WithMany("skins") + .HasForeignKey("ChampionEntityForeignKey"); + + b.Navigation("Champion"); + }); + + modelBuilder.Entity("EntityFramework.ChampionEntity", b => + { + b.Navigation("Skills"); + + b.Navigation("skins"); + }); + + modelBuilder.Entity("EntityFramework.RunePageEntity", b => + { + b.Navigation("Runes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EntityFramework/Migrations/20230325150121_MigrSkill.cs b/Sources/EntityFramework/Migrations/20230325150121_MigrSkill.cs new file mode 100644 index 0000000..4631e3a --- /dev/null +++ b/Sources/EntityFramework/Migrations/20230325150121_MigrSkill.cs @@ -0,0 +1,197 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EntityFramework.Migrations +{ + /// + public partial class MigrSkill : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Champions", + columns: table => new + { + Name = table.Column(type: "TEXT", maxLength: 50, nullable: false), + Bio = table.Column(type: "string", maxLength: 500, nullable: false), + Icon = table.Column(type: "TEXT", nullable: false), + Image = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Champions", x => x.Name); + }); + + migrationBuilder.CreateTable( + name: "Image", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Base64 = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Image", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Skills", + columns: table => new + { + Name = table.Column(type: "TEXT", nullable: false), + Type = table.Column(type: "INTEGER", nullable: false), + Description = table.Column(type: "TEXT", nullable: false), + ChampionEntityToSkillForeignKey = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Skills", x => x.Name); + table.ForeignKey( + name: "FK_Skills_Champions_ChampionEntityToSkillForeignKey", + column: x => x.ChampionEntityToSkillForeignKey, + principalTable: "Champions", + principalColumn: "Name"); + }); + + migrationBuilder.CreateTable( + name: "Skins", + columns: table => new + { + Name = table.Column(type: "TEXT", nullable: false), + Description = table.Column(type: "TEXT", nullable: true), + Icon = table.Column(type: "TEXT", nullable: false), + Image = table.Column(type: "TEXT", nullable: true), + Price = table.Column(type: "REAL", nullable: false), + ChampionEntityForeignKey = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Skins", x => x.Name); + table.ForeignKey( + name: "FK_Skins_Champions_ChampionEntityForeignKey", + column: x => x.ChampionEntityForeignKey, + principalTable: "Champions", + 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 => + { + table.PrimaryKey("PK_ChampionEntityRunePageEntity", x => new { x.ChampionName, x.RunePageEntitiesName }); + table.ForeignKey( + name: "FK_ChampionEntityRunePageEntity_Champions_ChampionName", + column: x => x.ChampionName, + principalTable: "Champions", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Rune", + columns: table => new + { + Name = table.Column(type: "TEXT", nullable: false), + RuneForeignKey = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Rune", x => x.Name); + }); + + 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.CreateIndex( + name: "IX_ChampionEntityRunePageEntity_RunePageEntitiesName", + table: "ChampionEntityRunePageEntity", + column: "RunePageEntitiesName"); + + migrationBuilder.CreateIndex( + name: "IX_Rune_RuneForeignKey", + table: "Rune", + column: "RuneForeignKey"); + + migrationBuilder.CreateIndex( + name: "IX_RunePage_RuneName", + table: "RunePage", + column: "RuneName"); + + migrationBuilder.CreateIndex( + name: "IX_Skills_ChampionEntityToSkillForeignKey", + table: "Skills", + column: "ChampionEntityToSkillForeignKey"); + + migrationBuilder.CreateIndex( + name: "IX_Skins_ChampionEntityForeignKey", + table: "Skins", + column: "ChampionEntityForeignKey"); + + migrationBuilder.AddForeignKey( + name: "FK_ChampionEntityRunePageEntity_RunePage_RunePageEntitiesName", + table: "ChampionEntityRunePageEntity", + column: "RunePageEntitiesName", + principalTable: "RunePage", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Rune_RunePage_RuneForeignKey", + table: "Rune", + column: "RuneForeignKey", + principalTable: "RunePage", + principalColumn: "Name"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Rune_RunePage_RuneForeignKey", + table: "Rune"); + + migrationBuilder.DropTable( + name: "ChampionEntityRunePageEntity"); + + migrationBuilder.DropTable( + name: "Image"); + + migrationBuilder.DropTable( + name: "Skills"); + + migrationBuilder.DropTable( + name: "Skins"); + + migrationBuilder.DropTable( + name: "Champions"); + + migrationBuilder.DropTable( + name: "RunePage"); + + migrationBuilder.DropTable( + name: "Rune"); + } + } +} diff --git a/Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs b/Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs new file mode 100644 index 0000000..c1b9974 --- /dev/null +++ b/Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs @@ -0,0 +1,222 @@ +// +using EntityFramework; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EntityFramework.Migrations +{ + [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") + .ValueGeneratedOnAdd() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Bio") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("string") + .HasColumnName("Bio"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Image") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("Champions", (string)null); + }); + + modelBuilder.Entity("EntityFramework.LargeImageEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Base64") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Image"); + }); + + modelBuilder.Entity("EntityFramework.RuneEntity", b => + { + b.Property("Name") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("RuneForeignKey") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.HasIndex("RuneForeignKey"); + + 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") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("ChampionEntityToSkillForeignKey") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.HasIndex("ChampionEntityToSkillForeignKey"); + + b.ToTable("Skills"); + }); + + modelBuilder.Entity("EntityFramework.SkinEntity", b => + { + b.Property("Name") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("ChampionEntityForeignKey") + .HasColumnType("TEXT"); + + b.Property("Description") + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Image") + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Name"); + + b.HasIndex("ChampionEntityForeignKey"); + + 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.RuneEntity", b => + { + b.HasOne("EntityFramework.RunePageEntity", "RunePage") + .WithMany("Runes") + .HasForeignKey("RuneForeignKey"); + + b.Navigation("RunePage"); + }); + + 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", "Champion") + .WithMany("Skills") + .HasForeignKey("ChampionEntityToSkillForeignKey"); + + b.Navigation("Champion"); + }); + + modelBuilder.Entity("EntityFramework.SkinEntity", b => + { + b.HasOne("EntityFramework.ChampionEntity", "Champion") + .WithMany("skins") + .HasForeignKey("ChampionEntityForeignKey"); + + b.Navigation("Champion"); + }); + + modelBuilder.Entity("EntityFramework.ChampionEntity", b => + { + b.Navigation("Skills"); + + b.Navigation("skins"); + }); + + modelBuilder.Entity("EntityFramework.RunePageEntity", b => + { + b.Navigation("Runes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EntityFramework/Program.cs b/Sources/EntityFramework/Program.cs index 56915f8..378e412 100644 --- a/Sources/EntityFramework/Program.cs +++ b/Sources/EntityFramework/Program.cs @@ -38,64 +38,101 @@ using ( var context = new LoLDbContext()) context.SaveChanges(); -IDataManager dataManager = new EFDataManager(); -IChampionsManager championsManager = dataManager.ChampionsMgr; -IEnumerable champions = await championsManager.GetItemsByName("A", 0, 1); -Console.WriteLine(champions.First().Name); - - -//using ( var context = new LoLDbContext()) -//{ -// //context.Add(new ChampionEntity{ Name = "test", Bio = "test", Icon = "test" } ); -// context.SaveChanges(); - -// ChampionEntity champ = context.Find("Akali"); - -// if( champ != null) -// { -// Console -// .WriteLine(champ.ToString()); - -// } -// else -// { -// Console.WriteLine("Not Found"); -// } - -// //Test BDD Skills -// 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 }; - -// champSkill.AddSkill(new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown }); -// champSkill.AddSkill(s2); -// champSkill.AddSkill(s3); - -// context.Add(champSkill); - -// context.SaveChanges(); + IDataManager dataManager = new EFDataManager(); + IChampionsManager championsManager = dataManager.ChampionsMgr; + IEnumerable champions = await championsManager.GetItemsByName("A", 0, 1); + //Console.WriteLine(champions.First().Name); + + + //using ( var context = new LoLDbContext()) + //{ + // //context.Add(new ChampionEntity{ Name = "test", Bio = "test", Icon = "test" } ); + // context.SaveChanges(); + + // ChampionEntity champ = context.Find("Akali"); + + // if( champ != null) + // { + // Console + // .WriteLine(champ.ToString()); + + // } + // else + // { + // Console.WriteLine("Not Found"); + // } + + // //Test BDD Skills + // 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 }; + + // champSkill.AddSkill(new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown }); + // champSkill.AddSkill(s2); + // champSkill.AddSkill(s3); + + // context.Add(champSkill); + + // context.SaveChanges(); + + + // //OneToMany + // Console.WriteLine("Champions : "); + // foreach (var champi in context.Champions.Include(a => a.skins)) + // { + // Console.WriteLine($"\t{champi.Name} : {champi.Bio}"); + // foreach (var s in champi.skins) + // { + // Console.WriteLine($"\t\t{s.Name}"); + // } + // } + + // Console.WriteLine(); + + // Console.WriteLine("Skin :"); + // foreach (var s in context.Skins) + // { + // Console.WriteLine($"\t{s.Name}: {s.Description} (Champion : {s.Champion.Name})"); + // } + + Console.WriteLine("\nAjout d'un Champion et 6 Skins...\n"); + + ChampionEntity captainMarvel = new ChampionEntity { Name = "Captain Marvel", Bio = "Mais que fait un avenger ici ??", Icon = "Icon.png" }; + SkinEntity[] skins = { new SkinEntity {Name = "La Fiesta", Champion = captainMarvel}, + new SkinEntity { Name = "Five Hundred Miles High", Champion = captainMarvel }, + new SkinEntity { Name = "Captain Marvel", Champion = captainMarvel }, + new SkinEntity { Name = "Time's Lie", Champion = captainMarvel }, + new SkinEntity { Name = "Lush Life", Champion = captainMarvel }, + new SkinEntity { Name = "Day Waves", Champion = captainMarvel } + }; + foreach (var s in skins) + { + captainMarvel.skins.Add(s); + } + context.Add(captainMarvel); + context.SaveChanges(); -// //OneToMany -// Console.WriteLine("Champions : "); -// foreach (var champi in context.Champions.Include(a => a.skins)) -// { -// Console.WriteLine($"\t{champi.Name} : {champi.Bio}"); -// foreach (var s in champi.skins) -// { -// Console.WriteLine($"\t\t{s.Name}"); -// } -// } -// Console.WriteLine(); + //OnetoMany Skill + ChampionEntity Levram = new ChampionEntity { Name = "Captain Levram", Bio="bio", Icon="/img" }; + SkillEntity[] morceaux = { new SkillEntity { Name = "La Fiesta", Description="SkillDesc", Type=EntityFramework.SkillType.Unknown, Champion= Levram }, + new SkillEntity { Name = "berserk", Description="SkillDesc1", Type=EntityFramework.SkillType.Unknown, Champion= Levram }, + new SkillEntity { Name = "taunt", Description = "SkillDesc2", Type = EntityFramework.SkillType.Unknown, Champion = Levram }, + new SkillEntity { Name = "fear", Description = "SkillDesc3", Type = EntityFramework.SkillType.Unknown, Champion = Levram }, + new SkillEntity { Name = "flashHeal", Description = "SkillDesc4", Type = EntityFramework.SkillType.Unknown, Champion = Levram }, + new SkillEntity { Name = "bubbuletp", Description = "SkillDesc5", Type = EntityFramework.SkillType.Unknown, Champion = Levram } + }; + foreach (var m in morceaux) + { + Levram.Skills.Add(m); + } + + context.Add(Levram); + context.SaveChanges(); -// Console.WriteLine("Skin :"); -// foreach (var s in context.Skins) -// { -// Console.WriteLine($"\t{s.Name}: {s.Description} (Champion : {s.Champion.Name})"); -// } var r1 = new RuneEntity { Name = "Rune1", Description = "aaa", Family = EnumRuneFamily.Domination, Image = new LargeImage("base") }; @@ -109,24 +146,4 @@ Console.WriteLine(champions.First().Name); context.Champions.AddRange(new[] { corichard, pintrand }); context.RunePage.AddRange(new[] { rp1, rp2 }); context.SaveChanges(); -} -// Console.WriteLine("\nAjout d'un Champion et 6 Skins...\n"); - -// ChampionEntity captainMarvel = new ChampionEntity { Name = "Captain Marvel", Bio="Mais que fait un avenger ici ??", Icon="Icon.png"}; -// SkinEntity[] skins = { new SkinEntity {Name = "La Fiesta", Champion = captainMarvel}, -// new SkinEntity { Name = "Five Hundred Miles High", Champion = captainMarvel }, -// new SkinEntity { Name = "Captain Marvel", Champion = captainMarvel }, -// new SkinEntity { Name = "Time's Lie", Champion = captainMarvel }, -// new SkinEntity { Name = "Lush Life", Champion = captainMarvel }, -// new SkinEntity { Name = "Day Waves", Champion = captainMarvel } -// }; -// foreach (var s in skins) -// { -// captainMarvel.skins.Add(s); -// } - -// context.Add(captainMarvel); -// context.SaveChanges(); - - -//} +} \ No newline at end of file diff --git a/Sources/EntityFramework/RuneEntity.cs b/Sources/EntityFramework/RuneEntity.cs index c9de7da..5047c19 100644 --- a/Sources/EntityFramework/RuneEntity.cs +++ b/Sources/EntityFramework/RuneEntity.cs @@ -20,5 +20,9 @@ namespace EntityFramework public EnumRuneFamily Family; public LargeImage Image; + + + //OtM + public RunePageEntity RunePage { get; set; } } } diff --git a/Sources/EntityFramework/RunePageEntity.cs b/Sources/EntityFramework/RunePageEntity.cs index 842806b..61270de 100644 --- a/Sources/EntityFramework/RunePageEntity.cs +++ b/Sources/EntityFramework/RunePageEntity.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; @@ -16,7 +17,11 @@ namespace EntityFramework public RuneEntity? Rune { get; set; } //? voir si cela pause probleme - public Dictionary Dico = new Dictionary(); + //public Dictionary Dico = new Dictionary(); + + // One to many pour l'instant, voir si on retransforme en dico : + public ICollection Runes { get; set; } + // Pour le many to many Champion *<---->* RunePage public ICollection Champion{ get; set; } diff --git a/Sources/EntityFramework/SkillEntity.cs b/Sources/EntityFramework/SkillEntity.cs index 505a427..22ed683 100644 --- a/Sources/EntityFramework/SkillEntity.cs +++ b/Sources/EntityFramework/SkillEntity.cs @@ -49,5 +49,9 @@ namespace EntityFramework // this.Description = Description; // this.Type = Type; //} + + + // One to many with champion : + public ChampionEntity Champion { get; set; } } } diff --git a/Sources/EntityFramework/SkinEntity.cs b/Sources/EntityFramework/SkinEntity.cs index e9650b3..f92a44d 100644 --- a/Sources/EntityFramework/SkinEntity.cs +++ b/Sources/EntityFramework/SkinEntity.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,7 +9,8 @@ namespace EntityFramework { public class SkinEntity //ONE TO MANY { - + + [Key] public string? Name { get; set; } public string? Description { get; set; } diff --git a/Sources/EntityFramework/StubbedContext.cs b/Sources/EntityFramework/StubbedContext.cs index 3731035..4bf0d84 100644 --- a/Sources/EntityFramework/StubbedContext.cs +++ b/Sources/EntityFramework/StubbedContext.cs @@ -42,10 +42,43 @@ namespace EntityFramework new { Name = "ruby", ChampionEntityForeignKey = "Pintrand", Description = "So What", Icon = "/Icon.png", Price = 10.0f } ); + //Skills + modelBuilder.Entity().HasData(new { Name="Skill", Description="Desc", Type= SkillType.Basic, ChampionEntityToSkillForeignKey= "Corichard" }, + new { Name = "Skill2", Description = "Desc", Type = SkillType.Basic, ChampionEntityToSkillForeignKey = "Corichard" }, + new { Name = "Skill3", Description = "Desc", Type = SkillType.Passive, ChampionEntityToSkillForeignKey = "Corichard" }, + new { Name = "Skill4", Description = "Desc", Type = SkillType.Unknown, ChampionEntityToSkillForeignKey = "Corichard" }, + new { Name = "Skill5", Description = "Desc", Type = SkillType.Basic, ChampionEntityToSkillForeignKey = "Corichard" }, + new { Name = "Skill6", Description = "Desc", Type = SkillType.Basic, ChampionEntityToSkillForeignKey = "Corichard" }, + new { Name = "Skill10", Description = "Desc", Type = SkillType.Basic, ChampionEntityToSkillForeignKey = "Pintrand" }, + new { Name = "Skill11", Description = "Desc", Type = SkillType.Unknown, ChampionEntityToSkillForeignKey = "Pintrand" }, + new { Name = "Skill12", Description = "Desc", Type = SkillType.Passive, ChampionEntityToSkillForeignKey = "Pintrand" }, + new { Name = "Skill13", Description = "Desc", Type = SkillType.Basic, ChampionEntityToSkillForeignKey = "Pintrand" }, + new { Name = "Skill14", Description = "Desc", Type = SkillType.Basic, ChampionEntityToSkillForeignKey = "Pintrand" } + ); + + + + modelBuilder.Entity().HasData(new { Name = "RP1", Rune = r1, Champion = corichard}, new { Name = "RP2", Rune = r2, Champion = pintrand} ); + + + + RunePageEntity rp11 = new RunePageEntity { Name = "rp11"}; + RunePageEntity rp21 = new RunePageEntity { Name = "rp21"}; + + modelBuilder.Entity().HasData(rp11, rp21); + + modelBuilder.Entity().HasData(new { Name = "Rune", Description = "Desc", Famille = EnumRuneFamily.Domination, RuneForeignKey = "rp11" }, + new{Name = "Rune2", Description = "Desc",Famille = EnumRuneFamily.Domination,RuneForeignKey = "rp11"}, + new { Name = "Rune3", Description = "Desc", Famille = EnumRuneFamily.Domination, RuneForeignKey = "rp21" }, + new { Name = "Rune4", Description = "Desc", Famille = EnumRuneFamily.Domination, RuneForeignKey = "rp21" } + ); } + + + } } diff --git a/Sources/EntityFramework/champion.db b/Sources/EntityFramework/champion.db new file mode 100644 index 0000000..c71528b Binary files /dev/null and b/Sources/EntityFramework/champion.db differ