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 e1ce9c7..8583611 100644 Binary files a/Sources/EntityFrameworkLOL/DBLOL.db and b/Sources/EntityFrameworkLOL/DBLOL.db differ diff --git a/Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs b/Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs index fcc602e..925512a 100644 --- a/Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs @@ -12,10 +12,13 @@ namespace EntityFrameworkLOL.Entities class ChampionEntity { [Key] + public int Id { get; set; } + + [Required] public string Name { get; set; } public string Bio { get; set; } - public string Icon { get; set; } + /*public string Icon { get; set; }*/ } } \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs b/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs index 7ceb423..296a68a 100644 --- a/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs @@ -11,6 +11,9 @@ namespace EntityFrameworkLOL.Entities class RuneEntity { [Key] + public int Id { get; set; } + + [Required] public string Name { get; set; } public string Description { get; set; } diff --git a/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs b/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs index 9412f33..67676c7 100644 --- a/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs @@ -11,6 +11,9 @@ namespace EntityFrameworkLOL.Entities class SkinEntity { [Key] + public int Id { get; set; } + + [Required] public string Name { get; set; } public string Description { get; set; } diff --git a/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.Designer.cs b/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.Designer.cs deleted file mode 100644 index da7a0e3..0000000 --- a/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.Designer.cs +++ /dev/null @@ -1,38 +0,0 @@ -// -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