From 6650ce89e06f84d2f8d230e48c228cfb35c07160 Mon Sep 17 00:00:00 2001 From: Louison PARANT Date: Sat, 4 Feb 2023 11:56:49 +0100 Subject: [PATCH] push EF database --- .../DBContexts/SQLiteContext.cs | 11 ++- Sources/EntityFrameworkLOL/DBLOL.db | Bin 45056 -> 45056 bytes .../Entities/ChampionEntity.cs | 5 +- .../EntityFrameworkLOL/Entities/RuneEntity.cs | 3 + .../EntityFrameworkLOL/Entities/SkinEntity.cs | 3 + ...0230202105714_MigrationWallah2.Designer.cs | 38 -------- .../20230202105714_MigrationWallah2.cs | 33 ------- ...0230204102144_MigrationWallah3.Designer.cs | 81 ++++++++++++++++++ .../20230204102144_MigrationWallah3.cs | 69 +++++++++++++++ .../Migrations/SQLiteContextModelSnapshot.cs | 47 +++++++++- Sources/EntityFrameworkLOL/Program.cs | 56 +++++++----- 11 files changed, 247 insertions(+), 99 deletions(-) delete mode 100644 Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.Designer.cs delete mode 100644 Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.cs create mode 100644 Sources/EntityFrameworkLOL/Migrations/20230204102144_MigrationWallah3.Designer.cs create mode 100644 Sources/EntityFrameworkLOL/Migrations/20230204102144_MigrationWallah3.cs diff --git a/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs b/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs index 8c31903..511998a 100644 --- a/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs +++ b/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs @@ -5,11 +5,18 @@ namespace EntityFrameworkLOL.DBContexts { class SQLiteContext : DbContext { - /*public DbSet Champion { get; set; } - public DbSet Skin { get; set; }*/ + 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"); + + public SQLiteContext() + { } + + public SQLiteContext(DbContextOptions options) + : base(options) + { } } } \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/DBLOL.db b/Sources/EntityFrameworkLOL/DBLOL.db index e1ce9c74d5f9994634429e98dacb045436979531..858361157c2dffac2361045c41627337790772a0 100644 GIT binary patch delta 1486 zcma)*O>7%Q6o6+v>vini+2>MOCNW#qL8VEWq#MVj6`-PZWVOMLi(*%lKShhPjaS*M z+x5CCT-qYMAZww3Ka;%35h?c5*&Ez*u;)nm6hJi z&b+_xy_q?GD|G%=Xf3rXM+gx+!s9&h>iBdzME#al8FTOO2IQ;w9WFeelB0CjI)@E-*CxTG5t+3>Hj4uvDIw26VK1HvAzh;%KscedajsPcPK|3jNu)Y5U36U8Enjc(kOGu)6UA0hA+T!stq0%Spye~{mk*W@Mn z2sT-jTl+*>NM^Lmw3gAbQ(9&!n_ZZ*mR!TL>dw=KZ5y@eLzCKMW?!t&P&=$?cQK6i z8y?gS-^Fl%7B)WIb2NZFOJEb;hu6S`5{!X>nAhaj<+BKRQf@s&3*0>z#eSPR;>C8@ z+=(pOW0RTE4j!7yF8H7CiTmLL|LlejhyWLPcpH9&@8M1O1TJpu(#}CEF7RYlpSi6YrqfU8y5mcXCw5j;C4KG}L2F$1~k1q9)m#S*;mC>lOB7v*B4) z!wveVFx|E%uqYRcmlf8HCL&Xcl|9Q@GToptB#sAzNMFMj@DW^rD@gP*68%gbexmEt zoz?m&HGumMDJIbEU}4%zH^9>loJi?58zy8uFsSKr#yT+YCwv2u8*m*D>MFv#1qG3& zxDK))(=@l;gK(54xpoV936H$n0UD&~QinvUM7vquU5mt(Kpmuuq70x!P=xLpQ+@~k E0@T)tRR910 delta 484 zcmZp8z|`=7X@az%2m=EHHx#o0X^DwC#)={gdht@c{6832_+%LPF7dDBli^#*D+GZ& z+&tWy6$Nf{O^)XNAuKA&*pyn5n3R(moSm5m!W@&cd1R#h5_5S!GW3cA1X2jX$Vyxl zlt4n0CvxlJuuq+ZO&nq$H%KMKKGw~b_>34uIQVul@ZaEH&)>!$%WuNZ&G(3J=VnEN zg?yWL%6WsNA2IOX -using EntityFrameworkLOL.DBContexts; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EntityFrameworkLOL.Migrations -{ - [DbContext(typeof(SQLiteContext))] - [Migration("20230202105714_MigrationWallah2")] - partial class MigrationWallah2 - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => - { - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("Description") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Name"); - - b.ToTable("Rune"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.cs b/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.cs deleted file mode 100644 index 0150ec7..0000000 --- a/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace EntityFrameworkLOL.Migrations -{ - /// - public partial class MigrationWallah2 : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Rune", - columns: table => new - { - Name = table.Column(type: "TEXT", nullable: false), - Description = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Rune", x => x.Name); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Rune"); - } - } -} diff --git a/Sources/EntityFrameworkLOL/Migrations/20230204102144_MigrationWallah3.Designer.cs b/Sources/EntityFrameworkLOL/Migrations/20230204102144_MigrationWallah3.Designer.cs new file mode 100644 index 0000000..956d301 --- /dev/null +++ b/Sources/EntityFrameworkLOL/Migrations/20230204102144_MigrationWallah3.Designer.cs @@ -0,0 +1,81 @@ +// +using EntityFrameworkLOL.DBContexts; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EntityFrameworkLOL.Migrations +{ + [DbContext(typeof(SQLiteContext))] + [Migration("20230204102144_MigrationWallah3")] + partial class MigrationWallah3 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.ChampionEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Bio") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Champion"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Rune"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.SkinEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Skin"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EntityFrameworkLOL/Migrations/20230204102144_MigrationWallah3.cs b/Sources/EntityFrameworkLOL/Migrations/20230204102144_MigrationWallah3.cs new file mode 100644 index 0000000..49e7a9d --- /dev/null +++ b/Sources/EntityFrameworkLOL/Migrations/20230204102144_MigrationWallah3.cs @@ -0,0 +1,69 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EntityFrameworkLOL.Migrations +{ + /// + public partial class MigrationWallah3 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Champion", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: false), + Bio = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Champion", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Rune", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: false), + Description = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Rune", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Skin", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: false), + Description = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Skin", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Champion"); + + migrationBuilder.DropTable( + name: "Rune"); + + migrationBuilder.DropTable( + name: "Skin"); + } + } +} diff --git a/Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs b/Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs index 59fd766..963e51a 100644 --- a/Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs +++ b/Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs @@ -16,19 +16,62 @@ namespace EntityFrameworkLOL.Migrations #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => + modelBuilder.Entity("EntityFrameworkLOL.Entities.ChampionEntity", b => { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Bio") + .IsRequired() + .HasColumnType("TEXT"); + b.Property("Name") + .IsRequired() .HasColumnType("TEXT"); + b.HasKey("Id"); + + b.ToTable("Champion"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + b.Property("Description") .IsRequired() .HasColumnType("TEXT"); - b.HasKey("Name"); + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); b.ToTable("Rune"); }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.SkinEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Skin"); + }); #pragma warning restore 612, 618 } } diff --git a/Sources/EntityFrameworkLOL/Program.cs b/Sources/EntityFrameworkLOL/Program.cs index e0798bd..70babcb 100644 --- a/Sources/EntityFrameworkLOL/Program.cs +++ b/Sources/EntityFrameworkLOL/Program.cs @@ -8,12 +8,12 @@ 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" }; + /*ChampionEntity akali = new ChampionEntity { Id = 1, Name = "Akali", Bio = "" }; + ChampionEntity aatrox = new ChampionEntity { Id = 2, Name = "Aatrox", Bio = "" }; + ChampionEntity ahri = new ChampionEntity { Id = 3, Name = "Ahri", Bio = "" }; + ChampionEntity bard = new ChampionEntity { Id = 4, Name = "Bard", Bio = "" }; + ChampionEntity alistar = new ChampionEntity { Id = 5, Name = "Alistar", Bio = "" }; + ChampionEntity akshan = new ChampionEntity { Id = 6, Name = "Akshan", Bio = "" }; using (var context = new ChampionContext()) { @@ -30,15 +30,15 @@ class Program var aChampion = context.Champion .Where(c => c.Name.StartsWith("A")) .First(); - Console.WriteLine($"{aChampion.Name} (with bio : {aChampion.Bio}"); + 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 = "" }; + RuneEntity conqueror = new RuneEntity { Id = 1, Name = "Conqueror", Description = "" }; + RuneEntity thriumph = new RuneEntity { Id = 2, Name = "Thriumph", Description = "" }; + RuneEntity alacrity = new RuneEntity { Id = 3, Name = "Legend : Alacrity", Description = "" }; + RuneEntity tenacity = new RuneEntity { Id = 4, Name = "Legend : Tenacity", Description = "" }; + RuneEntity laststand = new RuneEntity { Id = 5, Name = "Last Stand", Description = "" }; + RuneEntity laststand2 = new RuneEntity { Id = 6, Name = "Last Stand 2", Description = "" }; using (var context = new RuneContext()) { @@ -55,15 +55,15 @@ class Program var lRune = context.Rune .Where(r => r.Name.StartsWith("L")) .First(); - Console.WriteLine($"{lRune.Name} (with Description : {lRune.Description}"); + 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 = "" }; + SkinEntity stinger = new SkinEntity { Id = 1, Name = "Stinger", Description = "" }; + SkinEntity infernal = new SkinEntity { Id = 2, Name = "Infernal", Description = "" }; + SkinEntity allStar = new SkinEntity { Id = 3, Name = "All-Star", Description = "" }; + SkinEntity justicar = new SkinEntity { Id = 4, Name = "Justicar", Description = "" }; + SkinEntity mecha = new SkinEntity { Id = 5, Name = "Mecha", Description = "" }; + SkinEntity seaHunter = new SkinEntity { Id = 6, Name = "Sea Hunter", Description = "" }; using (var context = new SkinContext()) { @@ -80,18 +80,28 @@ class Program var iSkin = context.Skin .Where(s => s.Name.StartsWith("I")) .First(); - Console.WriteLine($"{iSkin.Name} (with Description : {iSkin.Description}"); + Console.WriteLine($"{iSkin.Name} (with Description : \"{iSkin.Description}\")"); Console.WriteLine("Updates the name of the Infernal Skin"); - iSkin.Name = "Infernal of Hell (Wallah)"; + iSkin.Description = "Hella Infernal (Wallah)"; context.SaveChanges(); - Console.WriteLine($"{iSkin.Name} (with Description : {iSkin.Description}"); + 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(); + }*/ + + using (var context = new ChampionContext()) + { + foreach (var c in context.Champion) + { + c.Bio = $"{c.Name}"; + Console.WriteLine($"{c.Name} - {c.Bio}"); + } + context.SaveChanges(); } } } \ No newline at end of file