diff --git a/Sources/APILOL/Mapper/ChampionMapper.cs b/Sources/APILOL/Mapper/ChampionMapper.cs index ecd6a18..cb116d8 100644 --- a/Sources/APILOL/Mapper/ChampionMapper.cs +++ b/Sources/APILOL/Mapper/ChampionMapper.cs @@ -25,9 +25,14 @@ namespace APILOL.Mapper return new Champion(champion.Name, champion.Class, champion.Icon, champion.Image.ToString(), champion.Bio); } + public static Champion ToModel(this ChampionEntity entity) + { + return new Champion(entity.Name, entity.Class, entity.Icon, entity.Image.Base64, entity.Bio); + } + public static ChampionEntity ToEntity(this Champion item) { - return new() + return new ChampionEntity { Name = item.Name, Bio = item.Bio, @@ -36,10 +41,5 @@ namespace APILOL.Mapper Image = new() { Base64 = item.Image.Base64 }, }; } - - public static Champion ToModel(this ChampionEntity entity) - { - return new(entity.Name, entity.Class, entity.Icon, entity.Image.Base64, entity.Bio); - } } } \ No newline at end of file diff --git a/Sources/APILOL/Mapper/RuneMapper.cs b/Sources/APILOL/Mapper/RuneMapper.cs index e1a582b..a3d3d78 100644 --- a/Sources/APILOL/Mapper/RuneMapper.cs +++ b/Sources/APILOL/Mapper/RuneMapper.cs @@ -1,4 +1,5 @@ using DTO; +using EntityFrameworkLOL.Entities; using Model; namespace APILOL.Mapper @@ -20,5 +21,21 @@ namespace APILOL.Mapper { return new Rune(rune.Name, rune.Family, rune.Image, rune.Image, rune.Description); } + + public static Rune ToModel(this RuneEntity entity) + { + return new Rune(entity.Name, entity.Family, "", entity.Image.Base64, entity.Description); + } + + public static RuneEntity ToEntity(this Rune item) + { + return new RuneEntity + { + Name = item.Name, + Description = item.Description, + Image = new() { Base64 = item.Image.Base64 }, + Family = item.Family, + }; + } } } diff --git a/Sources/APILOL/Mapper/RunePageMapper.cs b/Sources/APILOL/Mapper/RunePageMapper.cs index 6bc4de2..62d934f 100644 --- a/Sources/APILOL/Mapper/RunePageMapper.cs +++ b/Sources/APILOL/Mapper/RunePageMapper.cs @@ -1,4 +1,5 @@ using DTO; +using EntityFrameworkLOL.Entities; using Model; namespace APILOL.Mapper @@ -18,5 +19,18 @@ namespace APILOL.Mapper { return new RunePage(runePage.Name); } + + public static RunePage ToModel(this RunePageEntity entity) + { + return new RunePage(entity.Name); + } + + public static RunePageEntity ToEntity(this RunePage item) + { + return new RunePageEntity + { + Name = item.Name, + }; + } } } diff --git a/Sources/APILOL/Mapper/SkinMapper.cs b/Sources/APILOL/Mapper/SkinMapper.cs index 7fc1a2c..941ca37 100644 --- a/Sources/APILOL/Mapper/SkinMapper.cs +++ b/Sources/APILOL/Mapper/SkinMapper.cs @@ -1,4 +1,5 @@ using DTO; +using EntityFrameworkLOL.Entities; using Model; namespace APILOL.Mapper @@ -22,5 +23,23 @@ namespace APILOL.Mapper { return new Skin(skin.Name, skin.Champion.ToModel(),skin.Price, skin.Image, skin.Icon, skin.Description); } + + public static Skin ToModel(this SkinEntity entity) + { + return new Skin(entity.Name, entity.ChampionSkin.ToModel(), entity.Price, entity.Icon, entity.Description); + } + + public static SkinEntity ToEntity(this Skin item) + { + return new SkinEntity + { + Name = item.Name, + Description = item.Description, + Icon = item.Icon, + Price = item.Price, + ChampionSkin = item.Champion.ToEntity(), + Image = new() { Base64 = item.Image.Base64 }, + }; + } } -} +} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs b/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs index 8d9ad94..587ec70 100644 --- a/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs +++ b/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs @@ -1,5 +1,7 @@ using EntityFrameworkLOL.Entities; +using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Options; using Model; namespace EntityFrameworkLOL.DBContexts @@ -11,20 +13,30 @@ namespace EntityFrameworkLOL.DBContexts public DbSet Skin { get; set; } public DbSet Rune { get; set; } public DbSet RunePage { get; set; } + public DbSet Characteristic { get; set; } public DbSet Champion { get; set; } + public SQLiteContext() { } + + public SQLiteContext(DbContextOptions options) + : base(options) + { } + protected override void OnConfiguring(DbContextOptionsBuilder options) - => options.UseSqlite($"Data Source=DBLOL.db"); + { + //var connection = new SqliteConnection("DataSource=:memory:"); + var connection = new SqliteConnection("Data Source=DBLOL.db"); + connection.Open(); + options.UseSqlite(connection); + } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity().Property(i => i.Base64).ValueGeneratedOnAdd(); - modelBuilder.Entity().HasKey(c => new { c.Name, c.Champion }); + modelBuilder.Entity().HasKey(c => new { c.Name }); modelBuilder.Entity().Property(rp => rp.Name).ValueGeneratedOnAdd(); modelBuilder.Entity() - .HasMany(rp => rp.Runes) - .WithMany(r => r.RunePages) - .UsingEntity(); + .HasMany(rp => rp.Runes); modelBuilder.Entity() .HasMany(c => c.RunePages) .WithMany(rp => rp.Champions); @@ -41,13 +53,14 @@ namespace EntityFrameworkLOL.DBContexts Name = "WinKer", Bio = "Best front-end designer", Class = ChampionClass.Mage, - + Icon = "", }, new() { Name = "Jonquille", Bio = "Daffodil", Class = ChampionClass.Support, + Icon = "", } }); modelBuilder.Entity().HasData(new List() { diff --git a/Sources/EntityFrameworkLOL/DBLOL.db b/Sources/EntityFrameworkLOL/DBLOL.db index 5ecb42a..a3995b7 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 104744b..605733d 100644 --- a/Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs @@ -12,6 +12,7 @@ using Model; using static System.Net.Mime.MediaTypeNames; using System.Reflection.PortableExecutable; using System.Security.Claims; +using EntityFrameworkLOL.Entities; namespace EntityFrameworkLOL.Entities { @@ -23,17 +24,17 @@ namespace EntityFrameworkLOL.Entities [Required] public string Bio { get; set; } - public string Icon { get; set; } + public string? Icon { get; set; } [Required] public ChampionClass Class { get; set; } - public ImageEntity Image { get; set; } + public ImageEntity? Image { get; set; } public virtual ICollection Skills { get; set; } - public virtual ICollection Characteristics { get; set; } + //public virtual ICollection Characteristics { get; set; } - public ICollection RunePages { get; set; } + public virtual ICollection RunePages { get; set; } } } \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/CharacteristicEntity.cs b/Sources/EntityFrameworkLOL/Entities/CharacteristicEntity.cs index 7c7da71..ca87641 100644 --- a/Sources/EntityFrameworkLOL/Entities/CharacteristicEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/CharacteristicEntity.cs @@ -17,7 +17,8 @@ namespace EntityFrameworkLOL.Entities [Required] public int Value { get; set; } - [ForeignKey("ChampionEntity")] public ChampionEntity Champion { get; set; } + + //public virtual ICollection Champions { get; set; } } } \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs b/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs index 83bef82..4340ca3 100644 --- a/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs @@ -21,6 +21,6 @@ namespace EntityFrameworkLOL.Entities [Required] public RuneFamily Family { get; set; } - public ICollection RunePages { get; set; } + public virtual ICollection RunePages { get; set; } } } \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/RunePageEntity.cs b/Sources/EntityFrameworkLOL/Entities/RunePageEntity.cs index 6c30ddf..028bfe5 100644 --- a/Sources/EntityFrameworkLOL/Entities/RunePageEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/RunePageEntity.cs @@ -20,8 +20,8 @@ namespace EntityFrameworkLOL.Entities [Key] public string Name { get; set; } - public ICollection Runes { get; set; } + public virtual ICollection Runes { get; set; } - public ICollection Champions { get; set; } + public virtual ICollection Champions { get; set; } } } \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/RunePageRuneEntity.cs b/Sources/EntityFrameworkLOL/Entities/RunePageRuneEntity.cs index 02e256d..3bf8800 100644 --- a/Sources/EntityFrameworkLOL/Entities/RunePageRuneEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/RunePageRuneEntity.cs @@ -11,5 +11,9 @@ namespace EntityFrameworkLOL.Entities public class RunePageRuneEntity { public Category Category { get; set; } + + public RuneEntity Rune { get; set; } + + public RunePageEntity RunePage { get; set; } } } \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs b/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs index eb6496e..05954a1 100644 --- a/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs @@ -15,7 +15,7 @@ namespace EntityFrameworkLOL.Entities public string Description { get; set; } - public string Icon { get; set; } + public string? Icon { get; set; } public float Price { get; set; } diff --git a/Sources/EntityFrameworkLOL/Migrations/20230315161305_MigrationWallah6.Designer.cs b/Sources/EntityFrameworkLOL/Migrations/20230315161305_MigrationWallah6.Designer.cs new file mode 100644 index 0000000..6dd9313 --- /dev/null +++ b/Sources/EntityFrameworkLOL/Migrations/20230315161305_MigrationWallah6.Designer.cs @@ -0,0 +1,374 @@ +// +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("20230315161305_MigrationWallah6")] + partial class MigrationWallah6 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("ChampionEntityRunePageEntity", b => + { + b.Property("ChampionsName") + .HasColumnType("TEXT"); + + b.Property("RunePagesName") + .HasColumnType("TEXT"); + + b.HasKey("ChampionsName", "RunePagesName"); + + b.HasIndex("RunePagesName"); + + b.ToTable("ChampionEntityRunePageEntity"); + }); + + modelBuilder.Entity("ChampionEntitySkillEntity", b => + { + b.Property("ChampionsName") + .HasColumnType("TEXT"); + + b.Property("SkillsName") + .HasColumnType("TEXT"); + + b.HasKey("ChampionsName", "SkillsName"); + + b.HasIndex("SkillsName"); + + b.ToTable("ChampionEntitySkillEntity"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.ChampionEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Bio") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Class") + .HasColumnType("INTEGER"); + + b.Property("Icon") + .HasColumnType("TEXT"); + + b.Property("ImageBase64") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.HasIndex("ImageBase64"); + + b.ToTable("Champion"); + + b.HasData( + new + { + Name = "WinKer", + Bio = "Best front-end designer", + Class = 3, + Icon = "" + }, + new + { + Name = "Jonquille", + Bio = "Daffodil", + Class = 5, + Icon = "" + }); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.CharacteristicEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("ChampionName") + .HasColumnType("TEXT"); + + b.Property("Value") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.HasIndex("ChampionName"); + + b.ToTable("Characteristic"); + + b.HasData( + new + { + Name = "Front-end", + Value = 100 + }, + new + { + Name = "Back-end", + Value = 100 + }); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.ImageEntity", b => + { + b.Property("Base64") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.HasKey("Base64"); + + b.ToTable("Image"); + + b.HasData( + new + { + Base64 = "default" + }); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Family") + .HasColumnType("INTEGER"); + + b.Property("ImageBase64") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.HasIndex("ImageBase64"); + + b.ToTable("Rune"); + + b.HasData( + new + { + Name = "Mastering of Blue", + Description = "Blue shades", + Family = 2 + }, + new + { + Name = "Empty Shards", + Description = "Remove runes", + Family = 1 + }); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.RunePageEntity", b => + { + b.Property("Name") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("RunePage"); + + b.HasData( + new + { + Name = "FirstRunepage" + }); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.SkillEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.ToTable("Skill"); + + b.HasData( + new + { + Name = "Beautiful layout", + Description = "Bowl'In", + Type = 3 + }, + new + { + Name = "DB Support", + Description = "DB", + Type = 1 + }); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.SkinEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("ChampionSkinName") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Icon") + .HasColumnType("TEXT"); + + b.Property("ImageBase64") + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Name"); + + b.HasIndex("ChampionSkinName"); + + b.HasIndex("ImageBase64"); + + b.ToTable("Skin"); + + b.HasData( + new + { + Name = "Darker WinKer", + Description = "Be invisible in the darkness but never alone", + Icon = "default", + Price = 9.99f + }, + new + { + Name = "Summer Daffodil", + Description = "A jewel of Summer for all year long", + Icon = "default", + Price = 9.99f + }); + }); + + modelBuilder.Entity("RuneEntityRunePageEntity", b => + { + b.Property("RunePagesName") + .HasColumnType("TEXT"); + + b.Property("RunesName") + .HasColumnType("TEXT"); + + b.HasKey("RunePagesName", "RunesName"); + + b.HasIndex("RunesName"); + + b.ToTable("RuneEntityRunePageEntity"); + }); + + modelBuilder.Entity("ChampionEntityRunePageEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.ChampionEntity", null) + .WithMany() + .HasForeignKey("ChampionsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameworkLOL.Entities.RunePageEntity", null) + .WithMany() + .HasForeignKey("RunePagesName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ChampionEntitySkillEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.ChampionEntity", null) + .WithMany() + .HasForeignKey("ChampionsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameworkLOL.Entities.SkillEntity", null) + .WithMany() + .HasForeignKey("SkillsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.ChampionEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.ImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageBase64"); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.CharacteristicEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.ChampionEntity", "Champion") + .WithMany() + .HasForeignKey("ChampionName"); + + b.Navigation("Champion"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.ImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageBase64"); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.SkinEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.ChampionEntity", "ChampionSkin") + .WithMany() + .HasForeignKey("ChampionSkinName"); + + b.HasOne("EntityFrameworkLOL.Entities.ImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageBase64"); + + b.Navigation("ChampionSkin"); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("RuneEntityRunePageEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.RunePageEntity", null) + .WithMany() + .HasForeignKey("RunePagesName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameworkLOL.Entities.RuneEntity", null) + .WithMany() + .HasForeignKey("RunesName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EntityFrameworkLOL/Migrations/20230315161305_MigrationWallah6.cs b/Sources/EntityFrameworkLOL/Migrations/20230315161305_MigrationWallah6.cs new file mode 100644 index 0000000..5d59d7b --- /dev/null +++ b/Sources/EntityFrameworkLOL/Migrations/20230315161305_MigrationWallah6.cs @@ -0,0 +1,335 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace EntityFrameworkLOL.Migrations +{ + /// + public partial class MigrationWallah6 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Image", + columns: table => new + { + Base64 = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Image", x => x.Base64); + }); + + migrationBuilder.CreateTable( + name: "RunePage", + columns: table => new + { + Name = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RunePage", x => x.Name); + }); + + migrationBuilder.CreateTable( + name: "Skill", + columns: table => new + { + Name = table.Column(type: "TEXT", nullable: false), + Description = table.Column(type: "TEXT", nullable: false), + Type = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Skill", x => x.Name); + }); + + migrationBuilder.CreateTable( + name: "Champion", + columns: table => new + { + Name = table.Column(type: "TEXT", nullable: false), + Bio = table.Column(type: "TEXT", nullable: false), + Icon = table.Column(type: "TEXT", nullable: true), + Class = table.Column(type: "INTEGER", nullable: false), + ImageBase64 = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Champion", x => x.Name); + table.ForeignKey( + name: "FK_Champion_Image_ImageBase64", + column: x => x.ImageBase64, + principalTable: "Image", + principalColumn: "Base64"); + }); + + migrationBuilder.CreateTable( + name: "Rune", + columns: table => new + { + Name = table.Column(type: "TEXT", nullable: false), + Description = table.Column(type: "TEXT", nullable: false), + ImageBase64 = table.Column(type: "TEXT", nullable: true), + Family = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Rune", x => x.Name); + table.ForeignKey( + name: "FK_Rune_Image_ImageBase64", + column: x => x.ImageBase64, + principalTable: "Image", + principalColumn: "Base64"); + }); + + migrationBuilder.CreateTable( + name: "ChampionEntityRunePageEntity", + columns: table => new + { + ChampionsName = table.Column(type: "TEXT", nullable: false), + RunePagesName = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ChampionEntityRunePageEntity", x => new { x.ChampionsName, x.RunePagesName }); + table.ForeignKey( + name: "FK_ChampionEntityRunePageEntity_Champion_ChampionsName", + column: x => x.ChampionsName, + principalTable: "Champion", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ChampionEntityRunePageEntity_RunePage_RunePagesName", + column: x => x.RunePagesName, + principalTable: "RunePage", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ChampionEntitySkillEntity", + columns: table => new + { + ChampionsName = table.Column(type: "TEXT", nullable: false), + SkillsName = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ChampionEntitySkillEntity", x => new { x.ChampionsName, x.SkillsName }); + table.ForeignKey( + name: "FK_ChampionEntitySkillEntity_Champion_ChampionsName", + column: x => x.ChampionsName, + principalTable: "Champion", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ChampionEntitySkillEntity_Skill_SkillsName", + column: x => x.SkillsName, + principalTable: "Skill", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Characteristic", + columns: table => new + { + Name = table.Column(type: "TEXT", nullable: false), + Value = table.Column(type: "INTEGER", nullable: false), + ChampionName = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Characteristic", x => x.Name); + table.ForeignKey( + name: "FK_Characteristic_Champion_ChampionName", + column: x => x.ChampionName, + principalTable: "Champion", + principalColumn: "Name"); + }); + + migrationBuilder.CreateTable( + name: "Skin", + columns: table => new + { + Name = table.Column(type: "TEXT", nullable: false), + Description = table.Column(type: "TEXT", nullable: false), + Icon = table.Column(type: "TEXT", nullable: true), + Price = table.Column(type: "REAL", nullable: false), + ImageBase64 = table.Column(type: "TEXT", nullable: true), + ChampionSkinName = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Skin", x => x.Name); + table.ForeignKey( + name: "FK_Skin_Champion_ChampionSkinName", + column: x => x.ChampionSkinName, + principalTable: "Champion", + principalColumn: "Name"); + table.ForeignKey( + name: "FK_Skin_Image_ImageBase64", + column: x => x.ImageBase64, + principalTable: "Image", + principalColumn: "Base64"); + }); + + migrationBuilder.CreateTable( + name: "RuneEntityRunePageEntity", + columns: table => new + { + RunePagesName = table.Column(type: "TEXT", nullable: false), + RunesName = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RuneEntityRunePageEntity", x => new { x.RunePagesName, x.RunesName }); + table.ForeignKey( + name: "FK_RuneEntityRunePageEntity_RunePage_RunePagesName", + column: x => x.RunePagesName, + principalTable: "RunePage", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_RuneEntityRunePageEntity_Rune_RunesName", + column: x => x.RunesName, + principalTable: "Rune", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.InsertData( + table: "Champion", + columns: new[] { "Name", "Bio", "Class", "Icon", "ImageBase64" }, + values: new object[,] + { + { "Jonquille", "Daffodil", 5, "", null }, + { "WinKer", "Best front-end designer", 3, "", null } + }); + + migrationBuilder.InsertData( + table: "Characteristic", + columns: new[] { "Name", "ChampionName", "Value" }, + values: new object[,] + { + { "Back-end", null, 100 }, + { "Front-end", null, 100 } + }); + + migrationBuilder.InsertData( + table: "Image", + column: "Base64", + value: "default"); + + migrationBuilder.InsertData( + table: "Rune", + columns: new[] { "Name", "Description", "Family", "ImageBase64" }, + values: new object[,] + { + { "Empty Shards", "Remove runes", 1, null }, + { "Mastering of Blue", "Blue shades", 2, null } + }); + + migrationBuilder.InsertData( + table: "RunePage", + column: "Name", + value: "FirstRunepage"); + + migrationBuilder.InsertData( + table: "Skill", + columns: new[] { "Name", "Description", "Type" }, + values: new object[,] + { + { "Beautiful layout", "Bowl'In", 3 }, + { "DB Support", "DB", 1 } + }); + + migrationBuilder.InsertData( + table: "Skin", + columns: new[] { "Name", "ChampionSkinName", "Description", "Icon", "ImageBase64", "Price" }, + values: new object[,] + { + { "Darker WinKer", null, "Be invisible in the darkness but never alone", "default", null, 9.99f }, + { "Summer Daffodil", null, "A jewel of Summer for all year long", "default", null, 9.99f } + }); + + migrationBuilder.CreateIndex( + name: "IX_Champion_ImageBase64", + table: "Champion", + column: "ImageBase64"); + + migrationBuilder.CreateIndex( + name: "IX_ChampionEntityRunePageEntity_RunePagesName", + table: "ChampionEntityRunePageEntity", + column: "RunePagesName"); + + migrationBuilder.CreateIndex( + name: "IX_ChampionEntitySkillEntity_SkillsName", + table: "ChampionEntitySkillEntity", + column: "SkillsName"); + + migrationBuilder.CreateIndex( + name: "IX_Characteristic_ChampionName", + table: "Characteristic", + column: "ChampionName"); + + migrationBuilder.CreateIndex( + name: "IX_Rune_ImageBase64", + table: "Rune", + column: "ImageBase64"); + + migrationBuilder.CreateIndex( + name: "IX_RuneEntityRunePageEntity_RunesName", + table: "RuneEntityRunePageEntity", + column: "RunesName"); + + migrationBuilder.CreateIndex( + name: "IX_Skin_ChampionSkinName", + table: "Skin", + column: "ChampionSkinName"); + + migrationBuilder.CreateIndex( + name: "IX_Skin_ImageBase64", + table: "Skin", + column: "ImageBase64"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ChampionEntityRunePageEntity"); + + migrationBuilder.DropTable( + name: "ChampionEntitySkillEntity"); + + migrationBuilder.DropTable( + name: "Characteristic"); + + migrationBuilder.DropTable( + name: "RuneEntityRunePageEntity"); + + migrationBuilder.DropTable( + name: "Skin"); + + migrationBuilder.DropTable( + name: "Skill"); + + migrationBuilder.DropTable( + name: "RunePage"); + + migrationBuilder.DropTable( + name: "Rune"); + + migrationBuilder.DropTable( + name: "Champion"); + + migrationBuilder.DropTable( + name: "Image"); + } + } +} diff --git a/Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs b/Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs new file mode 100644 index 0000000..cc7759d --- /dev/null +++ b/Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs @@ -0,0 +1,371 @@ +// +using EntityFrameworkLOL.DBContexts; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EntityFrameworkLOL.Migrations +{ + [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("ChampionEntityRunePageEntity", b => + { + b.Property("ChampionsName") + .HasColumnType("TEXT"); + + b.Property("RunePagesName") + .HasColumnType("TEXT"); + + b.HasKey("ChampionsName", "RunePagesName"); + + b.HasIndex("RunePagesName"); + + b.ToTable("ChampionEntityRunePageEntity"); + }); + + modelBuilder.Entity("ChampionEntitySkillEntity", b => + { + b.Property("ChampionsName") + .HasColumnType("TEXT"); + + b.Property("SkillsName") + .HasColumnType("TEXT"); + + b.HasKey("ChampionsName", "SkillsName"); + + b.HasIndex("SkillsName"); + + b.ToTable("ChampionEntitySkillEntity"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.ChampionEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Bio") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Class") + .HasColumnType("INTEGER"); + + b.Property("Icon") + .HasColumnType("TEXT"); + + b.Property("ImageBase64") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.HasIndex("ImageBase64"); + + b.ToTable("Champion"); + + b.HasData( + new + { + Name = "WinKer", + Bio = "Best front-end designer", + Class = 3, + Icon = "" + }, + new + { + Name = "Jonquille", + Bio = "Daffodil", + Class = 5, + Icon = "" + }); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.CharacteristicEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("ChampionName") + .HasColumnType("TEXT"); + + b.Property("Value") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.HasIndex("ChampionName"); + + b.ToTable("Characteristic"); + + b.HasData( + new + { + Name = "Front-end", + Value = 100 + }, + new + { + Name = "Back-end", + Value = 100 + }); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.ImageEntity", b => + { + b.Property("Base64") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.HasKey("Base64"); + + b.ToTable("Image"); + + b.HasData( + new + { + Base64 = "default" + }); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Family") + .HasColumnType("INTEGER"); + + b.Property("ImageBase64") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.HasIndex("ImageBase64"); + + b.ToTable("Rune"); + + b.HasData( + new + { + Name = "Mastering of Blue", + Description = "Blue shades", + Family = 2 + }, + new + { + Name = "Empty Shards", + Description = "Remove runes", + Family = 1 + }); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.RunePageEntity", b => + { + b.Property("Name") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("RunePage"); + + b.HasData( + new + { + Name = "FirstRunepage" + }); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.SkillEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.ToTable("Skill"); + + b.HasData( + new + { + Name = "Beautiful layout", + Description = "Bowl'In", + Type = 3 + }, + new + { + Name = "DB Support", + Description = "DB", + Type = 1 + }); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.SkinEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("ChampionSkinName") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Icon") + .HasColumnType("TEXT"); + + b.Property("ImageBase64") + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Name"); + + b.HasIndex("ChampionSkinName"); + + b.HasIndex("ImageBase64"); + + b.ToTable("Skin"); + + b.HasData( + new + { + Name = "Darker WinKer", + Description = "Be invisible in the darkness but never alone", + Icon = "default", + Price = 9.99f + }, + new + { + Name = "Summer Daffodil", + Description = "A jewel of Summer for all year long", + Icon = "default", + Price = 9.99f + }); + }); + + modelBuilder.Entity("RuneEntityRunePageEntity", b => + { + b.Property("RunePagesName") + .HasColumnType("TEXT"); + + b.Property("RunesName") + .HasColumnType("TEXT"); + + b.HasKey("RunePagesName", "RunesName"); + + b.HasIndex("RunesName"); + + b.ToTable("RuneEntityRunePageEntity"); + }); + + modelBuilder.Entity("ChampionEntityRunePageEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.ChampionEntity", null) + .WithMany() + .HasForeignKey("ChampionsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameworkLOL.Entities.RunePageEntity", null) + .WithMany() + .HasForeignKey("RunePagesName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ChampionEntitySkillEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.ChampionEntity", null) + .WithMany() + .HasForeignKey("ChampionsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameworkLOL.Entities.SkillEntity", null) + .WithMany() + .HasForeignKey("SkillsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.ChampionEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.ImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageBase64"); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.CharacteristicEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.ChampionEntity", "Champion") + .WithMany() + .HasForeignKey("ChampionName"); + + b.Navigation("Champion"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.ImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageBase64"); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.SkinEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.ChampionEntity", "ChampionSkin") + .WithMany() + .HasForeignKey("ChampionSkinName"); + + b.HasOne("EntityFrameworkLOL.Entities.ImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageBase64"); + + b.Navigation("ChampionSkin"); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("RuneEntityRunePageEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.RunePageEntity", null) + .WithMany() + .HasForeignKey("RunePagesName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameworkLOL.Entities.RuneEntity", null) + .WithMany() + .HasForeignKey("RunesName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EntityFrameworkLOL/Program.cs b/Sources/EntityFrameworkLOL/Program.cs index 07c35d6..4fbb5ba 100644 --- a/Sources/EntityFrameworkLOL/Program.cs +++ b/Sources/EntityFrameworkLOL/Program.cs @@ -8,169 +8,5 @@ class Program { static void Main(string[] args) { - using (var context = new SQLiteContext()) { - if (context.Champion.Count() > 0) - { - foreach (var c in context.Champion.ToArray()) - { - context.Champion.Remove(c); - } - } - if (context.Rune.Count() > 0) - { - foreach (var r in context.Rune.ToArray()) - { - context.Rune.Remove(r); - } - } - if (context.Skin.Count() > 0) - { - foreach (var s in context.Skin.ToArray()) - { - context.Skin.Remove(s); - } - } - if (context.Skill.Count() > 0) - { - foreach (var s in context.Skill.ToArray()) - { - context.Skill.Remove(s); - } - } - if (context.RunePage.Count() > 0) - { - foreach (var rp in context.RunePage.ToArray()) - { - context.RunePage.Remove(rp); - } - } - if (context.ChampionClass.Count() > 0) - { - foreach (var cc in context.ChampionClass.ToArray()) - { - context.ChampionClass.Remove(cc); - } - } - if (context.RuneFamily.Count() > 0) - { - foreach (var rf in context.RuneFamily.ToArray()) - { - context.RuneFamily.Remove(rf); - } - } - if (context.SkillType.Count() > 0) - { - foreach (var st in context.SkillType.ToArray()) - { - context.SkillType.Remove(st); - } - } - if (context.Image.Count() > 0) - { - foreach (var i in context.Image.ToArray()) - { - context.Image.Remove(i); - } - } - context.SaveChanges(); - } - ChampionEntity akali = new ChampionEntity { Name = "Akali", Bio = "" }; - ChampionEntity aatrox = new ChampionEntity { Name = "Aatrox", Bio = "" }; - ChampionEntity ahri = new ChampionEntity { Name = "Ahri", Bio = "" }; - ChampionEntity bard = new ChampionEntity { Name = "Bard", Bio = "" }; - ChampionEntity alistar = new ChampionEntity { Name = "Alistar", Bio = "" }; - ChampionEntity akshan = new ChampionEntity { Name = "Akshan", Bio = "" }; - - using (var context = new SQLiteContext()) - { - // Crée des champions et les insère dans la base - Console.WriteLine("Creates and inserts new Champions"); - context.AddRange(new ChampionEntity[] { akali, aatrox, ahri, bard, alistar, akshan }); - /*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.Champion - .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 SQLiteContext()) - { - // Crée des Runes et les insère dans la base - Console.WriteLine("Creates and inserts new Runes"); - context.AddRange(new RuneEntity[] { conqueror, thriumph, alacrity, tenacity, laststand, laststand2 }); - /*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 SQLiteContext()) - { - // Crée des Skins et les insère dans la base - Console.WriteLine("Creates and inserts new Skins"); - context.AddRange(new SkinEntity[] { stinger, infernal, allStar, justicar, mecha, seaHunter }); - /*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.Description = "Hella Infernal (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(); - } - - using (var context = new SQLiteContext()) - { - foreach (var c in context.Champion) - { - c.Bio = $"{c.Name}"; - Console.WriteLine($"{c.Name} - {c.Bio}"); - } - context.SaveChanges(); - } } } \ No newline at end of file diff --git a/Sources/ManagersEF/EFManager.Champions.cs b/Sources/ManagersEF/EFManager.Champions.cs index 8e4b040..7dc361c 100644 --- a/Sources/ManagersEF/EFManager.Champions.cs +++ b/Sources/ManagersEF/EFManager.Champions.cs @@ -36,11 +36,6 @@ namespace ManagersEF public async Task> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false) { - - return parent.DbContext.Champion.GetItemsWithFilterAndOrdering( - c => c.Characteristics.Any(ch => ch.Name.Equals(charName)), - index, count, - orderingPropertyName, descending).Select(c => c.ToModel()); } public async Task> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false)