Ajout des liaisons One to many pour champion et skill, et pour runepage et rune, migration fonctionnel avec comme context le loldbcontext, mais pas avec le stubbed
continuous-integration/drone/push Build is passing Details

pull/36/head
Pierre Ferreira 2 years ago
parent a246358bbf
commit 3da8ab952a

@ -13,8 +13,9 @@ namespace EntityFramework
public DbSet<SkinEntity> Skins { get; set; }
public DbSet<LargeImageEntity> Image { get; set; }
public DbSet<SkillEntity> Skills { get; set; }
public DbSet<LargeImageEntity> Image { get; set; }
public DbSet<RuneEntity> Rune { get; set; }
@ -46,7 +47,8 @@ namespace EntityFramework
modelBuilder.Entity<ChampionEntity>().Property(entity => entity.Name)
.IsRequired()
.HasMaxLength(50);
.HasMaxLength(50)
.ValueGeneratedOnAdd();
modelBuilder.Entity<ChampionEntity>().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<ChampionEntity>().HasKey(c => c.Name); //définition de la clé primaire
//modelBuilder.Entity<ChampionEntity>().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<SkillEntity>().HasKey(s => s.Name); //définition de la clé primaire
modelBuilder.Entity<SkillEntity>().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<SkillEntity>()
.Property<string>("ChampionEntityToSkillForeignKey");
// Use the shadow property as a foreign key
modelBuilder.Entity<SkillEntity>()
.HasOne(s => s.Champion)
.WithMany(c => c.Skills)
.HasForeignKey("ChampionEntityToSkillForeignKey");
// Many to Many ChampionEntity - RunePageEntity
modelBuilder.Entity<RuneEntity>().HasKey(entity => entity.Name);
/// Many to Many ChampionEntity - RunePageEntity
modelBuilder.Entity<RunePageEntity>().HasKey(entity => entity.Name);
modelBuilder.Entity<RunePageEntity>().HasKey(entity => entity.Name);
modelBuilder.Entity<RunePageEntity>().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<RuneEntity>().HasKey(r => r.Name); //définition de la clé primaire
modelBuilder.Entity<RuneEntity>().Property(r => r.Name)
.ValueGeneratedOnAdd(); //définition du mode de génération de la clé : génération à l'insertion
modelBuilder.Entity<RuneEntity>()
.Property<string>("RuneForeignKey");
modelBuilder.Entity<RuneEntity>()
.HasOne(r => r.RunePage)
.WithMany(rp => rp.Runes)
.HasForeignKey("RuneForeignKey");
}
}
}

@ -0,0 +1,225 @@
// <auto-generated />
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
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("ChampionEntityRunePageEntity", b =>
{
b.Property<string>("ChampionName")
.HasColumnType("TEXT");
b.Property<string>("RunePageEntitiesName")
.HasColumnType("TEXT");
b.HasKey("ChampionName", "RunePageEntitiesName");
b.HasIndex("RunePageEntitiesName");
b.ToTable("ChampionEntityRunePageEntity");
});
modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Bio")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("string")
.HasColumnName("Bio");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Image")
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("Champions", (string)null);
});
modelBuilder.Entity("EntityFramework.LargeImageEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Base64")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Image");
});
modelBuilder.Entity("EntityFramework.RuneEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("RuneForeignKey")
.HasColumnType("TEXT");
b.HasKey("Name");
b.HasIndex("RuneForeignKey");
b.ToTable("Rune");
});
modelBuilder.Entity("EntityFramework.RunePageEntity", b =>
{
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("RuneName")
.HasColumnType("TEXT");
b.HasKey("Name");
b.HasIndex("RuneName");
b.ToTable("RunePage", (string)null);
});
modelBuilder.Entity("EntityFramework.SkillEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("ChampionEntityToSkillForeignKey")
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("Name");
b.HasIndex("ChampionEntityToSkillForeignKey");
b.ToTable("Skills");
});
modelBuilder.Entity("EntityFramework.SkinEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("ChampionEntityForeignKey")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Image")
.HasColumnType("TEXT");
b.Property<float>("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
}
}
}

@ -0,0 +1,197 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFramework.Migrations
{
/// <inheritdoc />
public partial class MigrSkill : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Champions",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
Bio = table.Column<string>(type: "string", maxLength: 500, nullable: false),
Icon = table.Column<string>(type: "TEXT", nullable: false),
Image = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Champions", x => x.Name);
});
migrationBuilder.CreateTable(
name: "Image",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Base64 = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Image", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Skills",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", nullable: false),
Type = table.Column<int>(type: "INTEGER", nullable: false),
Description = table.Column<string>(type: "TEXT", nullable: false),
ChampionEntityToSkillForeignKey = table.Column<string>(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<string>(type: "TEXT", nullable: false),
Description = table.Column<string>(type: "TEXT", nullable: true),
Icon = table.Column<string>(type: "TEXT", nullable: false),
Image = table.Column<string>(type: "TEXT", nullable: true),
Price = table.Column<float>(type: "REAL", nullable: false),
ChampionEntityForeignKey = table.Column<string>(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<string>(type: "TEXT", nullable: false),
RunePageEntitiesName = table.Column<string>(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<string>(type: "TEXT", nullable: false),
RuneForeignKey = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Rune", x => x.Name);
});
migrationBuilder.CreateTable(
name: "RunePage",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", nullable: false),
RuneName = table.Column<string>(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");
}
/// <inheritdoc />
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");
}
}
}

@ -0,0 +1,222 @@
// <auto-generated />
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<string>("ChampionName")
.HasColumnType("TEXT");
b.Property<string>("RunePageEntitiesName")
.HasColumnType("TEXT");
b.HasKey("ChampionName", "RunePageEntitiesName");
b.HasIndex("RunePageEntitiesName");
b.ToTable("ChampionEntityRunePageEntity");
});
modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Bio")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("string")
.HasColumnName("Bio");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Image")
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("Champions", (string)null);
});
modelBuilder.Entity("EntityFramework.LargeImageEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Base64")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Image");
});
modelBuilder.Entity("EntityFramework.RuneEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("RuneForeignKey")
.HasColumnType("TEXT");
b.HasKey("Name");
b.HasIndex("RuneForeignKey");
b.ToTable("Rune");
});
modelBuilder.Entity("EntityFramework.RunePageEntity", b =>
{
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("RuneName")
.HasColumnType("TEXT");
b.HasKey("Name");
b.HasIndex("RuneName");
b.ToTable("RunePage", (string)null);
});
modelBuilder.Entity("EntityFramework.SkillEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("ChampionEntityToSkillForeignKey")
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("Name");
b.HasIndex("ChampionEntityToSkillForeignKey");
b.ToTable("Skills");
});
modelBuilder.Entity("EntityFramework.SkinEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("ChampionEntityForeignKey")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Image")
.HasColumnType("TEXT");
b.Property<float>("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
}
}
}

@ -38,64 +38,101 @@ using ( var context = new LoLDbContext())
context.SaveChanges();
IDataManager dataManager = new EFDataManager();
IChampionsManager championsManager = dataManager.ChampionsMgr;
IEnumerable<Champion?> 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<ChampionEntity>("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<Champion?> 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<ChampionEntity>("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();
//}
}

@ -20,5 +20,9 @@ namespace EntityFramework
public EnumRuneFamily Family;
public LargeImage Image;
//OtM
public RunePageEntity RunePage { get; set; }
}
}

@ -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<EnumCategory, Rune> Dico = new Dictionary<EnumCategory, Rune>();
//public Dictionary<EnumCategory, Rune> Dico = new Dictionary<EnumCategory, Rune>();
// One to many pour l'instant, voir si on retransforme en dico :
public ICollection<RuneEntity> Runes { get; set; }
// Pour le many to many Champion *<---->* RunePage
public ICollection<ChampionEntity> Champion{ get; set; }

@ -49,5 +49,9 @@ namespace EntityFramework
// this.Description = Description;
// this.Type = Type;
//}
// One to many with champion :
public ChampionEntity Champion { get; set; }
}
}

@ -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; }

@ -42,10 +42,43 @@ namespace EntityFramework
new { Name = "ruby", ChampionEntityForeignKey = "Pintrand", Description = "So What", Icon = "/Icon.png", Price = 10.0f }
);
//Skills
modelBuilder.Entity<SkillEntity>().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<RunePageEntity>().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<RunePageEntity>().HasData(rp11, rp21);
modelBuilder.Entity<RuneEntity>().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" }
);
}
}
}

Loading…
Cancel
Save