From f01df10138647b987c6893a4d5bb9befef08d8a9 Mon Sep 17 00:00:00 2001
From: Pierre Ferreira
Date: Wed, 15 Mar 2023 16:36:25 +0100
Subject: [PATCH] finition du OneToMany des Skills ! :tada:
---
Sources/EntityFramework/ChampionEntity.cs | 5 +-
.../20230315145258_myMig.Designer.cs | 175 ++++++++++++++++++
.../Migrations/20230315145258_myMig.cs | 122 ++++++++++++
.../LoLDBContextWithStubModelSnapshot.cs | 172 +++++++++++++++++
Sources/EntityFramework/Program.cs | 12 +-
Sources/EntityFramework/SkillEntity.cs | 68 +++----
Sources/EntityFramework/SkinEntity.cs | 2 +-
Sources/EntityFramework/champion.db | Bin 0 -> 53248 bytes
8 files changed, 513 insertions(+), 43 deletions(-)
create mode 100644 Sources/EntityFramework/Migrations/20230315145258_myMig.Designer.cs
create mode 100644 Sources/EntityFramework/Migrations/20230315145258_myMig.cs
create mode 100644 Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs
diff --git a/Sources/EntityFramework/ChampionEntity.cs b/Sources/EntityFramework/ChampionEntity.cs
index d4a53e4..456b9ce 100644
--- a/Sources/EntityFramework/ChampionEntity.cs
+++ b/Sources/EntityFramework/ChampionEntity.cs
@@ -32,12 +32,12 @@ namespace EntityFramework
//public ImmutableHashSet Skills => skills.ToImmutableHashSet();
//private HashSet skills = new HashSet();
- public ICollection Skills { get; set; }
+ public ICollection Skills { get; set; } = new Collection();
//public ReadOnlyCollection Skins { get; private set; }
//private List skins = new();
- public ICollection skins { get; set; }
+ public ICollection skins { get; set; } = new Collection();
//public LargeImageEntity? Image { get; set; } ====> voir pour faire "plus propre" => créé une table pour l'entity Largeimage
public string? Image { get; set; }
@@ -69,7 +69,6 @@ namespace EntityFramework
public void RemoveSkill(SkillEntity skill)
=> Skills.Remove(skill);
-
public bool AddSkin(SkinEntity skin)
{
if (skins.Contains(skin))
diff --git a/Sources/EntityFramework/Migrations/20230315145258_myMig.Designer.cs b/Sources/EntityFramework/Migrations/20230315145258_myMig.Designer.cs
new file mode 100644
index 0000000..34ce7d8
--- /dev/null
+++ b/Sources/EntityFramework/Migrations/20230315145258_myMig.Designer.cs
@@ -0,0 +1,175 @@
+//
+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(LoLDBContextWithStub))]
+ [Migration("20230315145258_myMig")]
+ partial class myMig
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
+
+ modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
+ {
+ b.Property("Name")
+ .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("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 =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("Base64")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.ToTable("Image");
+ });
+
+ modelBuilder.Entity("EntityFramework.SkillEntity", b =>
+ {
+ b.Property("Name")
+ .HasColumnType("TEXT");
+
+ b.Property("ChampionEntityName")
+ .HasColumnType("TEXT");
+
+ b.Property("Description")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Type")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("Name");
+
+ b.HasIndex("ChampionEntityName");
+
+ b.ToTable("SkillEntity");
+ });
+
+ 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("EntityFramework.SkillEntity", b =>
+ {
+ b.HasOne("EntityFramework.ChampionEntity", null)
+ .WithMany("Skills")
+ .HasForeignKey("ChampionEntityName");
+ });
+
+ 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");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/Sources/EntityFramework/Migrations/20230315145258_myMig.cs b/Sources/EntityFramework/Migrations/20230315145258_myMig.cs
new file mode 100644
index 0000000..86b3a87
--- /dev/null
+++ b/Sources/EntityFramework/Migrations/20230315145258_myMig.cs
@@ -0,0 +1,122 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
+
+namespace EntityFramework.Migrations
+{
+ ///
+ public partial class myMig : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "Champion",
+ 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_Champion", 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: "SkillEntity",
+ columns: table => new
+ {
+ Name = table.Column(type: "TEXT", nullable: false),
+ Type = table.Column(type: "INTEGER", nullable: false),
+ Description = table.Column(type: "TEXT", nullable: false),
+ ChampionEntityName = table.Column(type: "TEXT", nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_SkillEntity", x => x.Name);
+ table.ForeignKey(
+ name: "FK_SkillEntity_Champion_ChampionEntityName",
+ column: x => x.ChampionEntityName,
+ principalTable: "Champion",
+ 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_Champion_ChampionEntityForeignKey",
+ column: x => x.ChampionEntityForeignKey,
+ principalTable: "Champion",
+ principalColumn: "Name");
+ });
+
+ migrationBuilder.InsertData(
+ table: "Champion",
+ columns: new[] { "Name", "Bio", "Icon", "Image" },
+ values: new object[,]
+ {
+ { "Aatrox", "", "", null },
+ { "Ahri", "", "", null },
+ { "Akali", "", "", null },
+ { "Akshan", "", "", null },
+ { "Alistar", "", "", null },
+ { "Bard", "", "", null }
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_SkillEntity_ChampionEntityName",
+ table: "SkillEntity",
+ column: "ChampionEntityName");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Skins_ChampionEntityForeignKey",
+ table: "Skins",
+ column: "ChampionEntityForeignKey");
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "Image");
+
+ migrationBuilder.DropTable(
+ name: "SkillEntity");
+
+ migrationBuilder.DropTable(
+ name: "Skins");
+
+ migrationBuilder.DropTable(
+ name: "Champion");
+ }
+ }
+}
diff --git a/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs b/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs
new file mode 100644
index 0000000..1bbd357
--- /dev/null
+++ b/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs
@@ -0,0 +1,172 @@
+//
+using EntityFramework;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace EntityFramework.Migrations
+{
+ [DbContext(typeof(LoLDBContextWithStub))]
+ partial class LoLDBContextWithStubModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
+
+ modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
+ {
+ b.Property("Name")
+ .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("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 =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("Base64")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.ToTable("Image");
+ });
+
+ modelBuilder.Entity("EntityFramework.SkillEntity", b =>
+ {
+ b.Property("Name")
+ .HasColumnType("TEXT");
+
+ b.Property("ChampionEntityName")
+ .HasColumnType("TEXT");
+
+ b.Property("Description")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Type")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("Name");
+
+ b.HasIndex("ChampionEntityName");
+
+ b.ToTable("SkillEntity");
+ });
+
+ 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("EntityFramework.SkillEntity", b =>
+ {
+ b.HasOne("EntityFramework.ChampionEntity", null)
+ .WithMany("Skills")
+ .HasForeignKey("ChampionEntityName");
+ });
+
+ 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");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/Sources/EntityFramework/Program.cs b/Sources/EntityFramework/Program.cs
index a0c478c..818faa5 100644
--- a/Sources/EntityFramework/Program.cs
+++ b/Sources/EntityFramework/Program.cs
@@ -4,10 +4,10 @@ using Microsoft.EntityFrameworkCore;
using ( var context = new LoLDbContext())
{
- context.Add(new ChampionEntity{ Name = "test", Bio = "test", Icon = "test" } );
+ //context.Add(new ChampionEntity{ Name = "test", Bio = "test", Icon = "test" } );
context.SaveChanges();
- ChampionEntity champ = context.Find(1);
+ ChampionEntity champ = context.Find("Akali");
if( champ != null)
{
@@ -23,11 +23,11 @@ using ( var context = new LoLDbContext())
//Test BDD Skills
ChampionEntity champSkill = new ChampionEntity { Name="nomSkill", Bio="bioSkill", Icon="iconSkill" };
- SkillEntity s1 = new SkillEntity("Skill1", "desc", SkillType.Unknown);
- SkillEntity s2 = new SkillEntity("Skill2", "desc2", SkillType.Ultimate);
- SkillEntity s3 = new SkillEntity("Skill3", "desc3", SkillType.Passive);
+ //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(s1);
+ champSkill.AddSkill(new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown });
champSkill.AddSkill(s2);
champSkill.AddSkill(s3);
diff --git a/Sources/EntityFramework/SkillEntity.cs b/Sources/EntityFramework/SkillEntity.cs
index d370410..505a427 100644
--- a/Sources/EntityFramework/SkillEntity.cs
+++ b/Sources/EntityFramework/SkillEntity.cs
@@ -10,42 +10,44 @@ namespace EntityFramework
public class SkillEntity
{
- public SkillType Type { get; private set; }
+ public SkillType Type { get; set; }
[Key]
- public string Name
- {
- get => name;
- private init
- {
- if (string.IsNullOrWhiteSpace(value))
- {
- throw new ArgumentException("a Skill needs a name");
- }
- name = value;
- }
- }
- private readonly string name = null!;
+ public string Name { get; set; }
+ //public string Name
+ //{
+ // get => name;
+ // private init
+ // {
+ // if (string.IsNullOrWhiteSpace(value))
+ // {
+ // throw new ArgumentException("a Skill needs a name");
+ // }
+ // name = value;
+ // }
+ //}
+ //private readonly string name = null!;
- public string Description
- {
- get => description;
- set
- {
- if (string.IsNullOrWhiteSpace(value))
- {
- description = "";
- return;
- }
- description = value;
- }
- }
- private string description = "";
+ public string Description { get; set; }
+ //public string Description
+ //{
+ // get => description;
+ // set
+ // {
+ // if (string.IsNullOrWhiteSpace(value))
+ // {
+ // description = "";
+ // return;
+ // }
+ // description = value;
+ // }
+ //}
+ //private string description = "";
- public SkillEntity(string Name, string Description, SkillType Type) {
- this.name = Name;
- this.Description = Description;
- this.Type = Type;
- }
+ //public SkillEntity(string Name, string Description, SkillType Type) {
+ // this.name = Name;
+ // this.Description = Description;
+ // this.Type = Type;
+ //}
}
}
diff --git a/Sources/EntityFramework/SkinEntity.cs b/Sources/EntityFramework/SkinEntity.cs
index 8c98d8b..e9650b3 100644
--- a/Sources/EntityFramework/SkinEntity.cs
+++ b/Sources/EntityFramework/SkinEntity.cs
@@ -42,7 +42,7 @@ namespace EntityFramework
//}
//private string description = "";
- public string Icon { get; set; }
+ public string Icon { get; set; } = "";
//public LargeImageEntity Image { get; set; }
diff --git a/Sources/EntityFramework/champion.db b/Sources/EntityFramework/champion.db
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..d4cefafe01938de63ed498a197e95c56e3139632 100644
GIT binary patch
literal 53248
zcmeI*Pi)&%90zbaFLD0wZIdQbwybaIfkmsznywTvrjd0{7d3xMnn8zzBCqvYYl+j@
z>9ihOv?JOLi6iX7g~No{g%g4U2P7meppC->2PP0)KnRHo&rY2G={8iR4Zc>B_`T=%
z{QUXZQSw|ni?3$&y2dWm%&J;vQ^H=s;}KqAOb`SQe?p>n8ZC*fBqB)+0=m
zpN-N#g-D<(?D?9082x6?d(oF8KZWNa9|doO4+Z|>1(+ZJ0SG_<0ucD`3T%ZVez_ov
zTc>nmMZ1<+DlcBv4XZr6rdHSWnxPnVy}p^QnVP<8%xjxYX>_)zq)H0Qd_8ePkFVf@h08U$e=#Cg#)U#`s6Ot-!pp+
z@x)u9pkJ0{@w!!4FIMbT8kX}EYOb-AI+In}n->i+KE<8NtfVZJSiZm?=d)QhTgWe#
zim6P##NrF{4e2;rC}wi0;srLZTo`XwKC4;FroLY10f;x-;Pu_o%yK)s*>tO@s;+7S
zsw|lLGSBB>%eK1X))^X(zBPCDKi%wqi?%h>yUWB`x=>Uyb9s9UcML!8Us@?D`B`O=
zwe}J_E{#Y;Ly1I4l26H^;Owl{l?wl$Tvj*gH7DKNbtj$Zgtv9SUmhD1uaCHKb0gic
z*97`v=q|)p`$&;&*BcPe(&jqX=W$o&lww~121L6jtlc5%+_l=fMSpPIF0~@lnrVcn
z(aui6X}CW)EYkr=&W!C4mR48n;JAt4f+Weuj)@nX05zj&X;(HhV_EA-`nv+vQ+U+i
zN9s7Qnb>;9=Nzot)M+zg9}dow)Kx$3uw+BALI||>D=e?3V8ygmFw-e<_ch0x9B>Lr<8F9PdY+*we}KLr(BJ5N`W^j>eoAlCcX$RS2tWV=5P$##AOHafKmY;|fB*y@Lg1xPf5Bq(w*r;IC
zs?HTG7xkL+s`FxJCMfw1M5DqP)m(}Ad1oo4J*gc96h>)1*4i5MOWbUgGA=Dd<=lt
zOWGpx5#^Y38-OX#3jgiaDfdc%5l_1)N$jGeTO{*q{sRXZwI=Nnx4^#spU`{u
z_5VNf7fcX<00bZa0SG_<0uX=z1Rwwb2t0)X_I&^vV+Eu&n{=-KcXB7~^ZybZ7wBF3
z34NPZX^tl_K>z{}fB*y_009U<00Izz00jQW0;7`uh!7P5iIQH`p0ik1*Shb^ci872
zbr#5OSZloaQg6A}Emv7u*Z2+lyX%h=|4FBQTED8Xa~sBrsjaY_UePRePG4Q?Uiz@7
z+1goklfBM=NWkhY9~1ovr?u|v?v#E0U!v~{^jCV1e$IdU?*pE|1OW&@00Izz00bZa
z0SG_<0uX?};}O_Hj)?7X1}REL#nz~T&q=vs2;PI_q&Q^6fY?j6#s@t6NFvz({h!b~
z0{xxe0pQN#*)*&L0uX=z1Rwwb2tWV=5P$##AOL~g66pMmK+>7;gh?#edHugcZ`kMm
z@6s>m$Mk)kzytvZKmY;|fB*y_009U<00Izzz`rT5pCrWY6ZBGlmajj{+n+`Hvj&|1
F{~Ka`fTsWe
literal 0
HcmV?d00001