From b41894300de911adc330e3aac0ffaeea0835351a Mon Sep 17 00:00:00 2001 From: Corentin R <76619184+Koroh63@users.noreply.github.com> Date: Sun, 19 Mar 2023 23:55:09 +0100 Subject: [PATCH] Problem not fix --- Sources/EntityFramework/LoLDbContext.cs | 2 +- .../Manager/EFDataManager.Champions.cs | 10 +- .../EntityFramework/Mapper/ChampionMapper.cs | 5 + .../20230319224555_myMig.Designer.cs | 175 ++++++++++++++++++ .../Migrations/20230319224555_myMig.cs | 122 ++++++++++++ .../LoLDBContextWithStubModelSnapshot.cs | 172 +++++++++++++++++ Sources/EntityFramework/champion.db | Bin 0 -> 53248 bytes 7 files changed, 481 insertions(+), 5 deletions(-) create mode 100644 Sources/EntityFramework/Migrations/20230319224555_myMig.Designer.cs create mode 100644 Sources/EntityFramework/Migrations/20230319224555_myMig.cs create mode 100644 Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs create mode 100644 Sources/EntityFramework/champion.db diff --git a/Sources/EntityFramework/LoLDbContext.cs b/Sources/EntityFramework/LoLDbContext.cs index af9be3b..003ff03 100644 --- a/Sources/EntityFramework/LoLDbContext.cs +++ b/Sources/EntityFramework/LoLDbContext.cs @@ -35,7 +35,7 @@ namespace EntityFramework protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity().HasKey(entity => entity.Name); - modelBuilder.Entity().ToTable("Champion"); + modelBuilder.Entity().ToTable("Champions"); //modelBuilder.Entity().Property(entity => entity.Id) // .ValueGeneratedOnAdd(); diff --git a/Sources/EntityFramework/Manager/EFDataManager.Champions.cs b/Sources/EntityFramework/Manager/EFDataManager.Champions.cs index 9bfd098..c0ecda6 100644 --- a/Sources/EntityFramework/Manager/EFDataManager.Champions.cs +++ b/Sources/EntityFramework/Manager/EFDataManager.Champions.cs @@ -56,13 +56,15 @@ namespace EntityFramework.Manager throw new NotImplementedException(); } - public Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) + public async Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); using (var context = new LoLDBContextWithStub()) { - IEnumerable champ = context.Champions.Where(c => c.Name.Contains(substring)); - //return champ.ToList().Where(l => l.toCh) + + var champ = context.Champions.Where(c => c.Name.Contains(substring)).AsEnumerable(); + return champ.Select(c => c.ToChampion()).ToList(); + + } } diff --git a/Sources/EntityFramework/Mapper/ChampionMapper.cs b/Sources/EntityFramework/Mapper/ChampionMapper.cs index 2a3e9f4..da146b2 100644 --- a/Sources/EntityFramework/Mapper/ChampionMapper.cs +++ b/Sources/EntityFramework/Mapper/ChampionMapper.cs @@ -13,5 +13,10 @@ namespace EntityFramework.Mapper return new ChampionEntity { Name = champion.Name, Bio = champion.Bio, Icon = champion.Icon }; } + public static Champion ToChampion(this ChampionEntity champion) + { + return new Champion(champion.Name,bio: champion.Bio,icon: champion.Icon); + } + } } diff --git a/Sources/EntityFramework/Migrations/20230319224555_myMig.Designer.cs b/Sources/EntityFramework/Migrations/20230319224555_myMig.Designer.cs new file mode 100644 index 0000000..2a90b9d --- /dev/null +++ b/Sources/EntityFramework/Migrations/20230319224555_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("20230319224555_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("Champions", (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/20230319224555_myMig.cs b/Sources/EntityFramework/Migrations/20230319224555_myMig.cs new file mode 100644 index 0000000..0e61c80 --- /dev/null +++ b/Sources/EntityFramework/Migrations/20230319224555_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: "Champions", + 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_Champions", 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_Champions_ChampionEntityName", + column: x => x.ChampionEntityName, + principalTable: "Champions", + 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_Champions_ChampionEntityForeignKey", + column: x => x.ChampionEntityForeignKey, + principalTable: "Champions", + principalColumn: "Name"); + }); + + migrationBuilder.InsertData( + table: "Champions", + 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: "Champions"); + } + } +} diff --git a/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs b/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs new file mode 100644 index 0000000..e00a86a --- /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("Champions", (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/champion.db b/Sources/EntityFramework/champion.db new file mode 100644 index 0000000000000000000000000000000000000000..d6b07a7f3f047be19725f261f5ceb2230711d230 GIT binary patch literal 53248 zcmeI)&2QUu9LI4xX`YjLNKB>-RLi}r+En#nS;b+3v~x$)F6q(?wFeZL)U;O9q_b18 z9#ho6gTG)`?uaWAf)fW$z+o2-2nliIXD7}>lN2W9kfFELw0`>i{PpW&Td~u2_vyCX zw6xC~&WYL7R;8O#C?tKPX_6#`#496S!4MN8Gr@%TDff+!8x2W|m3K4B-%>hWm2Ui~ zyv+P?^)2h%Uz*t{8M(5d2;v^MlpYYV9Jf)KoA}EYW4KG(D=OVBv_S-I{`RhAZ>7pf7xxPQ+AIl`p?& znxECYP1ariTe7poa&CRw=@9aqOy?FJjy7 zmJ_rY8^_R=`|IEA)Ze8Yf6VCGX0c@C9~Zn`yf%MP;HFVB3LD0*);&yIFPU~0ndHJk zGO9jQWywEW-RCv&2DxIMH5>kP=ipuT^GRJC$71UIynOk7kX(>;-*FQkN-1I?$3|%=f)RON33f1~{)4M`U<}6-lr%P^c1PF6(}w>K!DQo6H9vn% zFx_Ijc!G(`}2As=MRSSxq8NSn)KzX<(`#``GV;AiBTvAr_{RXS`Y3A=V2#Gaqzab z!ZCGjPQI}G(t=Rk?#RqwiQW0VGW(++b6x3c)mLe^HoKu~Zqu>rheOBVYg}2x-Ym~V zRby^k;@v7L%iYmPYfp};YisgF(FdqhjLj$Zp<{YiI`?DSZ8n_qkuyVsFeBILA$9xo zLcR7HJf@=&ZaYrn;H=vG#B$ue%W^N1Zx;9Q@kM#H+$3ayYB5EUm0AtuBACvT{G0%~np%#p8>$#ihlS zq}VT6c_oQ21_Tg5009ILKmY**5I_I{1Q2+`1=MghG3p_J_xXQR`C3x`R9-1RE8i>M zhzSM+5I_I{1Q0*~0R#|0009ILm;!-BG;%AGk=9M;ARUR^7NfbE_{#>X?}3-9y)sPe6({H6S^{Hpwi3g4DH&jBLI@T}Z^3NVuht723<0|0^I*kXD(EQ00IagfB*srAbfB*srAb