From bb2bcb3a30ab88f0942bb3f52b3b8f04cf81f0e6 Mon Sep 17 00:00:00 2001 From: Louison PARANT Date: Thu, 2 Feb 2023 12:04:31 +0100 Subject: [PATCH] modif Entity --- .../{ => DBContexts}/ChampionContext.cs | 7 +- .../DBContexts/RuneContext.cs | 13 +++ .../DBContexts/SQLiteContext.cs | 15 +++ .../DBContexts/SkinContext.cs | 13 +++ Sources/EntityFrameworkLOL/DBLOL.db | Bin 20480 -> 45056 bytes .../{ => Entities}/ChampionEntity.cs | 3 +- .../EntityFrameworkLOL/Entities/RuneEntity.cs | 18 ++++ .../EntityFrameworkLOL/Entities/SkinEntity.cs | 22 ++++ .../EntityFrameworkLOL.DBLOL.db | Bin 20480 -> 0 bytes .../EntityFrameworkLOL.csproj | 4 + ...230202105714_MigrationWallah2.Designer.cs} | 18 ++-- ....cs => 20230202105714_MigrationWallah2.cs} | 11 +- ...pshot.cs => SQLiteContextModelSnapshot.cs} | 16 ++- Sources/EntityFrameworkLOL/Program.cs | 99 +++++++++++++++++- Sources/StubLib/StubData.Champions.cs | 3 +- 15 files changed, 207 insertions(+), 35 deletions(-) rename Sources/EntityFrameworkLOL/{ => DBContexts}/ChampionContext.cs (52%) create mode 100644 Sources/EntityFrameworkLOL/DBContexts/RuneContext.cs create mode 100644 Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs create mode 100644 Sources/EntityFrameworkLOL/DBContexts/SkinContext.cs rename Sources/EntityFrameworkLOL/{ => Entities}/ChampionEntity.cs (85%) create mode 100644 Sources/EntityFrameworkLOL/Entities/RuneEntity.cs create mode 100644 Sources/EntityFrameworkLOL/Entities/SkinEntity.cs delete mode 100644 Sources/EntityFrameworkLOL/EntityFrameworkLOL.DBLOL.db rename Sources/EntityFrameworkLOL/Migrations/{20230201163336_MigrationWallah.Designer.cs => 20230202105714_MigrationWallah2.Designer.cs} (64%) rename Sources/EntityFrameworkLOL/Migrations/{20230201163336_MigrationWallah.cs => 20230202105714_MigrationWallah2.cs} (66%) rename Sources/EntityFrameworkLOL/Migrations/{ChampionContextModelSnapshot.cs => SQLiteContextModelSnapshot.cs} (63%) diff --git a/Sources/EntityFrameworkLOL/ChampionContext.cs b/Sources/EntityFrameworkLOL/DBContexts/ChampionContext.cs similarity index 52% rename from Sources/EntityFrameworkLOL/ChampionContext.cs rename to Sources/EntityFrameworkLOL/DBContexts/ChampionContext.cs index 719926b..f7d3a11 100644 --- a/Sources/EntityFrameworkLOL/ChampionContext.cs +++ b/Sources/EntityFrameworkLOL/DBContexts/ChampionContext.cs @@ -1,10 +1,11 @@ -using Microsoft.EntityFrameworkCore; +using EntityFrameworkLOL.Entities; +using Microsoft.EntityFrameworkCore; -namespace EntityFrameworkLOL +namespace EntityFrameworkLOL.DBContexts { class ChampionContext : DbContext { - public DbSet Champions { get; set; } + public DbSet Champion { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder options) => options.UseSqlite($"Data Source=DBLOL.db"); diff --git a/Sources/EntityFrameworkLOL/DBContexts/RuneContext.cs b/Sources/EntityFrameworkLOL/DBContexts/RuneContext.cs new file mode 100644 index 0000000..daa69f9 --- /dev/null +++ b/Sources/EntityFrameworkLOL/DBContexts/RuneContext.cs @@ -0,0 +1,13 @@ +using EntityFrameworkLOL.Entities; +using Microsoft.EntityFrameworkCore; + +namespace EntityFrameworkLOL.DBContexts +{ + class RuneContext : DbContext + { + public DbSet Rune { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder options) + => options.UseSqlite($"Data Source=DBLOL.db"); + } +} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs b/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs new file mode 100644 index 0000000..8c31903 --- /dev/null +++ b/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs @@ -0,0 +1,15 @@ +using EntityFrameworkLOL.Entities; +using Microsoft.EntityFrameworkCore; + +namespace EntityFrameworkLOL.DBContexts +{ + class SQLiteContext : DbContext + { + /*public DbSet Champion { get; set; } + public DbSet Skin { get; set; }*/ + public DbSet Rune { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder options) + => options.UseSqlite($"Data Source=DBLOL.db"); + } +} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/DBContexts/SkinContext.cs b/Sources/EntityFrameworkLOL/DBContexts/SkinContext.cs new file mode 100644 index 0000000..5628c53 --- /dev/null +++ b/Sources/EntityFrameworkLOL/DBContexts/SkinContext.cs @@ -0,0 +1,13 @@ +using EntityFrameworkLOL.Entities; +using Microsoft.EntityFrameworkCore; + +namespace EntityFrameworkLOL.DBContexts +{ + class SkinContext : DbContext + { + public DbSet Skin { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder options) + => options.UseSqlite($"Data Source=DBLOL.db"); + } +} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/DBLOL.db b/Sources/EntityFrameworkLOL/DBLOL.db index 6e8e7c513bb882be2ef983154f94548171efa3cd..e1ce9c74d5f9994634429e98dacb045436979531 100644 GIT binary patch literal 45056 zcmeI&O-~a+7{KveTG~=**BHneBgtA55u@1MR;%$MVvP+@u++B$*;J^y5n63a)FT|c zdG$MZFnZOq2hW~7naDTr#?cv|&|P;yFGlKr$n<6U%crB&a2zH=(u zY@f70aZdTH>$RPqkQWLGUm^)S3ssZu{wM zoySM!TD7^*aGtcpX#C0`E@t%dP!NMWrftgGKF?K`R%%sQBkp8nlPlT%u6nD(pI)`L zp~i!+S{~Cj&o=6d zD+{gL)kf2IY8HAT`g|^EYWkkXHhr5z;sZ7&KV%c~LGpv5ebwG+FSU6stMw<>MFRx^ z1Q0*~0R#|0009ILKmdV%L0}{nn$)edl}U>mGkrd1X6>Etd zRQFjYh`D2Ymk6Tn7~j=_h$qHxVW77&CSXkbj)w|;+qnlU0?7S; z@uPnV0tg_000IagfB*srAb0tg_000IagfB*srARq+T z|7RK?fB*srAbfB*srAbhxcqv}~9}FzKuNn9*@vr55%{PCuqCh#X zWuqZ8ySThOW0PS?Vp2}3b4FrrL1unlF`U8T9OUX4;;Inh=;Y(7pad76JdxX!v3T+W z9?{9SxeeG1S=hu~zQ||H$i~QjgMt6XWj3%p82Il2 N`B(Ti-_uu800239HcS8j diff --git a/Sources/EntityFrameworkLOL/ChampionEntity.cs b/Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs similarity index 85% rename from Sources/EntityFrameworkLOL/ChampionEntity.cs rename to Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs index f693c37..fcc602e 100644 --- a/Sources/EntityFrameworkLOL/ChampionEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs @@ -5,8 +5,9 @@ using System.Threading.Tasks; using System.Collections.Generic; using System.Text; using System.ComponentModel.DataAnnotations; +using System.Xml.Linq; -namespace EntityFrameworkLOL +namespace EntityFrameworkLOL.Entities { class ChampionEntity { diff --git a/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs b/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs new file mode 100644 index 0000000..7ceb423 --- /dev/null +++ b/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs @@ -0,0 +1,18 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Linq; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel.DataAnnotations; + +namespace EntityFrameworkLOL.Entities +{ + class RuneEntity + { + [Key] + public string Name { get; set; } + + public string Description { get; set; } + } +} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs b/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs new file mode 100644 index 0000000..9412f33 --- /dev/null +++ b/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Linq; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel.DataAnnotations; + +namespace EntityFrameworkLOL.Entities +{ + class SkinEntity + { + [Key] + public string Name { get; set; } + + public string Description { get; set; } + + /*public string Icon { get; set; } + + public float Price { get; set; }*/ + } +} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/EntityFrameworkLOL.DBLOL.db b/Sources/EntityFrameworkLOL/EntityFrameworkLOL.DBLOL.db deleted file mode 100644 index e40710c96492a259a9812802b2d7b5b83a14c274..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20480 zcmeI&zi!h&9Ki9jleQ4a4VxvF92pQuD2g44Fp@?_SWT0V8fXV(nZ~7-k{BFUg0X!O zo`9EOV&Vn*0*st1;ugzcVrljL$tT~P?K}TI_ToSLuLe;X%Hueh2dV6cdqUU6b18)o zx+)v0tRibyR}Hn+uGQC7b;w%TF`)tm+4+X?)qfn#;HHX*bRev@NsS)y_wkY5KnNVlVoT1ZkG* z%V?R#$(Pbj{qOWk_qn3T$8@KK(=Ljv8K^{OoW#@9qx4OfEY-;thE*D_zG=SeuG1); z$G1wmE9#EAligK@Dq8)APz!+o0tg_000IagfB*srAb7PIV0R#|0009ILKmY**5I_KdTP%=$|L6Jt7GGdeLjVB;5I_I{1Q0*~0R#|0 HKneT?YZ%8* diff --git a/Sources/EntityFrameworkLOL/EntityFrameworkLOL.csproj b/Sources/EntityFrameworkLOL/EntityFrameworkLOL.csproj index d683ca4..40baca6 100644 --- a/Sources/EntityFrameworkLOL/EntityFrameworkLOL.csproj +++ b/Sources/EntityFrameworkLOL/EntityFrameworkLOL.csproj @@ -20,4 +20,8 @@ + + + + \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Migrations/20230201163336_MigrationWallah.Designer.cs b/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.Designer.cs similarity index 64% rename from Sources/EntityFrameworkLOL/Migrations/20230201163336_MigrationWallah.Designer.cs rename to Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.Designer.cs index e24c7dc..da7a0e3 100644 --- a/Sources/EntityFrameworkLOL/Migrations/20230201163336_MigrationWallah.Designer.cs +++ b/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.Designer.cs @@ -1,5 +1,5 @@ // -using EntityFrameworkLOL; +using EntityFrameworkLOL.DBContexts; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; @@ -9,9 +9,9 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace EntityFrameworkLOL.Migrations { - [DbContext(typeof(ChampionContext))] - [Migration("20230201163336_MigrationWallah")] - partial class MigrationWallah + [DbContext(typeof(SQLiteContext))] + [Migration("20230202105714_MigrationWallah2")] + partial class MigrationWallah2 { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -19,22 +19,18 @@ namespace EntityFrameworkLOL.Migrations #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - modelBuilder.Entity("EntityFrameworkLOL.ChampionEntity", b => + modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => { b.Property("Name") .HasColumnType("TEXT"); - b.Property("Bio") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Icon") + b.Property("Description") .IsRequired() .HasColumnType("TEXT"); b.HasKey("Name"); - b.ToTable("Champions"); + b.ToTable("Rune"); }); #pragma warning restore 612, 618 } diff --git a/Sources/EntityFrameworkLOL/Migrations/20230201163336_MigrationWallah.cs b/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.cs similarity index 66% rename from Sources/EntityFrameworkLOL/Migrations/20230201163336_MigrationWallah.cs rename to Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.cs index eb2dfc8..0150ec7 100644 --- a/Sources/EntityFrameworkLOL/Migrations/20230201163336_MigrationWallah.cs +++ b/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.cs @@ -5,22 +5,21 @@ namespace EntityFrameworkLOL.Migrations { /// - public partial class MigrationWallah : Migration + public partial class MigrationWallah2 : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( - name: "Champions", + name: "Rune", columns: table => new { Name = table.Column(type: "TEXT", nullable: false), - Bio = table.Column(type: "TEXT", nullable: false), - Icon = table.Column(type: "TEXT", nullable: false) + Description = table.Column(type: "TEXT", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_Champions", x => x.Name); + table.PrimaryKey("PK_Rune", x => x.Name); }); } @@ -28,7 +27,7 @@ namespace EntityFrameworkLOL.Migrations protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( - name: "Champions"); + name: "Rune"); } } } diff --git a/Sources/EntityFrameworkLOL/Migrations/ChampionContextModelSnapshot.cs b/Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs similarity index 63% rename from Sources/EntityFrameworkLOL/Migrations/ChampionContextModelSnapshot.cs rename to Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs index 351bf79..59fd766 100644 --- a/Sources/EntityFrameworkLOL/Migrations/ChampionContextModelSnapshot.cs +++ b/Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs @@ -1,5 +1,5 @@ // -using EntityFrameworkLOL; +using EntityFrameworkLOL.DBContexts; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; @@ -8,30 +8,26 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace EntityFrameworkLOL.Migrations { - [DbContext(typeof(ChampionContext))] - partial class ChampionContextModelSnapshot : ModelSnapshot + [DbContext(typeof(SQLiteContext))] + partial class SQLiteContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - modelBuilder.Entity("EntityFrameworkLOL.ChampionEntity", b => + modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => { b.Property("Name") .HasColumnType("TEXT"); - b.Property("Bio") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Icon") + b.Property("Description") .IsRequired() .HasColumnType("TEXT"); b.HasKey("Name"); - b.ToTable("Champions"); + b.ToTable("Rune"); }); #pragma warning restore 612, 618 } diff --git a/Sources/EntityFrameworkLOL/Program.cs b/Sources/EntityFrameworkLOL/Program.cs index 3751555..7271191 100644 --- a/Sources/EntityFrameworkLOL/Program.cs +++ b/Sources/EntityFrameworkLOL/Program.cs @@ -1,2 +1,97 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using EntityFrameworkLOL.DBContexts; +using EntityFrameworkLOL.Entities; +using System.Linq; +using System; +using System.Text; + +class Program +{ + static void Main(string[] args) + { + /*ChampionEntity akali = new ChampionEntity {Name="Akali"}; + ChampionEntity aatrox = new ChampionEntity { Name = "Aatrox" }; + ChampionEntity ahri = new ChampionEntity { Name = "Ahri" }; + ChampionEntity bard = new ChampionEntity { Name = "Bard" }; + ChampionEntity alistar = new ChampionEntity { Name = "Alistar" }; + ChampionEntity akshan = new ChampionEntity { Name = "Akshan" }; + + using (var context = new ChampionContext()) + { + // Crée des champions et les insère dans la base + Console.WriteLine("Creates and inserts new Champions"); + context.Add(akali); + context.Add(aatrox); + context.Add(ahri); + context.Add(bard); + context.Add(alistar); + context.Add(akshan); + context.SaveChanges(); + Console.WriteLine("Creates and executes a query retrieving the first Champion of the database whose name starts with an \"A\":"); + var aChampion = context.Champions + .Where(c => c.Name.StartsWith("A")) + .First(); + Console.WriteLine($"{aChampion.Name} (with bio : {aChampion.Bio}"); + }*/ + + RuneEntity conqueror = new RuneEntity { Name = "Conqueror", Description = "" }; + RuneEntity thriumph = new RuneEntity { Name = "Thriumph", Description = "" }; + RuneEntity alacrity = new RuneEntity { Name = "Legend : Alacrity", Description = "" }; + RuneEntity tenacity = new RuneEntity { Name = "Legend : Tenacity", Description = "" }; + RuneEntity laststand = new RuneEntity { Name = "Last Stand", Description = "" }; + RuneEntity laststand2 = new RuneEntity { Name = "Last Stand 2", Description = "" }; + + using (var context = new RuneContext()) + { + // Crée des Runes et les insère dans la base + Console.WriteLine("Creates and inserts new Runes"); + context.Add(conqueror); + context.Add(thriumph); + context.Add(alacrity); + context.Add(tenacity); + context.Add(laststand); + context.Add(laststand2); + context.SaveChanges(); + Console.WriteLine("Creates and executes a query retrieving the first Runes of the database whose name starts with an \"L\":"); + var lRune = context.Rune + .Where(r => r.Name.StartsWith("L")) + .First(); + Console.WriteLine($"{lRune.Name} (with Description : {lRune.Description}"); + } + + /*SkinEntity stinger = new SkinEntity { Name = "Stinger", Description = "" }; + SkinEntity infernal = new SkinEntity { Name = "Infernal", Description = "" }; + SkinEntity allStar = new SkinEntity { Name = "All-Star", Description = "" }; + SkinEntity justicar = new SkinEntity { Name = "Justicar", Description = "" }; + SkinEntity mecha = new SkinEntity { Name = "Mecha", Description = "" }; + SkinEntity seaHunter = new SkinEntity { Name = "Sea Hunter", Description = "" }; + + using (var context = new SkinContext()) + { + // Crée des Skins et les insère dans la base + Console.WriteLine("Creates and inserts new Skins"); + context.Add(stinger); + context.Add(infernal); + context.Add(allStar); + context.Add(justicar); + context.Add(mecha); + context.Add(seaHunter); + context.SaveChanges(); + Console.WriteLine("Creates and executes a query retrieving the first Skins of the database whose name starts with an \"I\":"); + var iSkin = context.Skin + .Where(s => s.Name.StartsWith("I")) + .First(); + Console.WriteLine($"{iSkin.Name} (with Description : {iSkin.Description}"); + + Console.WriteLine("Updates the name of the Infernal Skin"); + iSkin.Name = "Infernal of Hell (Wallah)"; + context.SaveChanges(); + Console.WriteLine($"{iSkin.Name} (with Description : {iSkin.Description}"); + + Console.WriteLine("Deletes one item from the database"); + var droid = context.Skin + .SingleOrDefault(s => s.Name.Equals("Infernal")); + context.Remove(droid); + context.SaveChanges(); + }*/ + } +} \ No newline at end of file diff --git a/Sources/StubLib/StubData.Champions.cs b/Sources/StubLib/StubData.Champions.cs index ad19275..8df8028 100644 --- a/Sources/StubLib/StubData.Champions.cs +++ b/Sources/StubLib/StubData.Champions.cs @@ -96,5 +96,4 @@ namespace StubLib => parent.champions.UpdateItem(oldItem, newItem); } } -} - +} \ No newline at end of file