From 10d4be1b54b2fe01a85a0d049b5225320f5bfe4b Mon Sep 17 00:00:00 2001 From: Pierre Ferreira Date: Sat, 11 Mar 2023 12:05:44 +0100 Subject: [PATCH] =?UTF-8?q?continuation=20de=20la=20recherche=20du=20probl?= =?UTF-8?q?eme=20:=20seed,=20apparament=20li=C3=A9=20a=20des=20conflits=20?= =?UTF-8?q?de=20OneToMany?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/EntityFramework/ChampionEntity.cs | 3 +- .../EntityFramework/EntityFramework.csproj | 4 + Sources/EntityFramework/LargeImageEntity.cs | 2 +- Sources/EntityFramework/LoLDbContext.cs | 3 + .../20230301152530_SkillMigration.Designer.cs | 85 ------------------ .../20230301152530_SkillMigration.cs | 63 ------------- .../Migrations/LoLDbContextModelSnapshot.cs | 82 ----------------- Sources/EntityFramework/SkinEntity.cs | 6 +- Sources/EntityFramework/StubbedContext.cs | 32 ++++--- Sources/EntityFramework/champion.db | Bin 32768 -> 32768 bytes 10 files changed, 35 insertions(+), 245 deletions(-) delete mode 100644 Sources/EntityFramework/Migrations/20230301152530_SkillMigration.Designer.cs delete mode 100644 Sources/EntityFramework/Migrations/20230301152530_SkillMigration.cs delete mode 100644 Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs diff --git a/Sources/EntityFramework/ChampionEntity.cs b/Sources/EntityFramework/ChampionEntity.cs index 8452958..8a975d2 100644 --- a/Sources/EntityFramework/ChampionEntity.cs +++ b/Sources/EntityFramework/ChampionEntity.cs @@ -39,7 +39,8 @@ namespace EntityFramework public ICollection skins { get; set; } - public LargeImageEntity Image { get; set; } = new LargeImageEntity(); + //public LargeImageEntity? Image { get; set; } ====> voir pour faire "plus propre" => créé une table pour l'entity Largeimage + public string? Image { get; set; } diff --git a/Sources/EntityFramework/EntityFramework.csproj b/Sources/EntityFramework/EntityFramework.csproj index 66899d0..6ca2f66 100644 --- a/Sources/EntityFramework/EntityFramework.csproj +++ b/Sources/EntityFramework/EntityFramework.csproj @@ -17,4 +17,8 @@ + + + + diff --git a/Sources/EntityFramework/LargeImageEntity.cs b/Sources/EntityFramework/LargeImageEntity.cs index f86eade..b925a83 100644 --- a/Sources/EntityFramework/LargeImageEntity.cs +++ b/Sources/EntityFramework/LargeImageEntity.cs @@ -11,7 +11,7 @@ namespace EntityFramework public class LargeImageEntity { - [Key] + public int Id { get; set; } public string Base64 { get; set; } //public LargeImageEntity(string base64) diff --git a/Sources/EntityFramework/LoLDbContext.cs b/Sources/EntityFramework/LoLDbContext.cs index 7c8ea74..91b440a 100644 --- a/Sources/EntityFramework/LoLDbContext.cs +++ b/Sources/EntityFramework/LoLDbContext.cs @@ -13,6 +13,9 @@ namespace EntityFramework public DbSet Skins { get; set; } + public DbSet Image { get; set; } + + public LoLDbContext() { } diff --git a/Sources/EntityFramework/Migrations/20230301152530_SkillMigration.Designer.cs b/Sources/EntityFramework/Migrations/20230301152530_SkillMigration.Designer.cs deleted file mode 100644 index 94bb55c..0000000 --- a/Sources/EntityFramework/Migrations/20230301152530_SkillMigration.Designer.cs +++ /dev/null @@ -1,85 +0,0 @@ -// -using System; -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(LoLDbContext))] - [Migration("20230301152530_SkillMigration")] - partial class SkillMigration - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("EntityFramework.ChampionEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Bio") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("string") - .HasColumnName("Bio"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Champion", (string)null); - }); - - modelBuilder.Entity("EntityFramework.Skill", b => - { - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("ChampionEntityId") - .HasColumnType("INTEGER"); - - b.Property("Description") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Type") - .HasColumnType("INTEGER"); - - b.HasKey("Name"); - - b.HasIndex("ChampionEntityId"); - - b.ToTable("Skill"); - }); - - modelBuilder.Entity("EntityFramework.Skill", b => - { - b.HasOne("EntityFramework.ChampionEntity", null) - .WithMany("Skills") - .HasForeignKey("ChampionEntityId"); - }); - - modelBuilder.Entity("EntityFramework.ChampionEntity", b => - { - b.Navigation("Skills"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Sources/EntityFramework/Migrations/20230301152530_SkillMigration.cs b/Sources/EntityFramework/Migrations/20230301152530_SkillMigration.cs deleted file mode 100644 index ce0154c..0000000 --- a/Sources/EntityFramework/Migrations/20230301152530_SkillMigration.cs +++ /dev/null @@ -1,63 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace EntityFramework.Migrations -{ - /// - public partial class SkillMigration : 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", maxLength: 50, nullable: false), - Bio = table.Column(type: "string", maxLength: 500, nullable: false), - Icon = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Champion", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Skill", - columns: table => new - { - Name = table.Column(type: "TEXT", nullable: false), - Type = table.Column(type: "INTEGER", nullable: false), - Description = table.Column(type: "TEXT", nullable: false), - ChampionEntityId = table.Column(type: "INTEGER", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Skill", x => x.Name); - table.ForeignKey( - name: "FK_Skill_Champion_ChampionEntityId", - column: x => x.ChampionEntityId, - principalTable: "Champion", - principalColumn: "Id"); - }); - - migrationBuilder.CreateIndex( - name: "IX_Skill_ChampionEntityId", - table: "Skill", - column: "ChampionEntityId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Skill"); - - migrationBuilder.DropTable( - name: "Champion"); - } - } -} diff --git a/Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs b/Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs deleted file mode 100644 index 0abeee1..0000000 --- a/Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs +++ /dev/null @@ -1,82 +0,0 @@ -// -using System; -using EntityFramework; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EntityFramework.Migrations -{ - [DbContext(typeof(LoLDbContext))] - partial class LoLDbContextModelSnapshot : 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("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Bio") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("string") - .HasColumnName("Bio"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Champion", (string)null); - }); - - modelBuilder.Entity("EntityFramework.Skill", b => - { - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("ChampionEntityId") - .HasColumnType("INTEGER"); - - b.Property("Description") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Type") - .HasColumnType("INTEGER"); - - b.HasKey("Name"); - - b.HasIndex("ChampionEntityId"); - - b.ToTable("Skill"); - }); - - modelBuilder.Entity("EntityFramework.Skill", b => - { - b.HasOne("EntityFramework.ChampionEntity", null) - .WithMany("Skills") - .HasForeignKey("ChampionEntityId"); - }); - - modelBuilder.Entity("EntityFramework.ChampionEntity", b => - { - b.Navigation("Skills"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Sources/EntityFramework/SkinEntity.cs b/Sources/EntityFramework/SkinEntity.cs index 6035674..8c98d8b 100644 --- a/Sources/EntityFramework/SkinEntity.cs +++ b/Sources/EntityFramework/SkinEntity.cs @@ -43,7 +43,11 @@ namespace EntityFramework //private string description = ""; public string Icon { get; set; } - public LargeImageEntity Image { get; set; } + + + //public LargeImageEntity Image { get; set; } + public string? Image { get; set; } + public float Price { get; set; } public ChampionEntity Champion { get; set; } diff --git a/Sources/EntityFramework/StubbedContext.cs b/Sources/EntityFramework/StubbedContext.cs index 53efd24..a7936e3 100644 --- a/Sources/EntityFramework/StubbedContext.cs +++ b/Sources/EntityFramework/StubbedContext.cs @@ -9,26 +9,34 @@ namespace EntityFramework { public class StubbedContext : LoLDbContext { + //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + //{ + // optionsBuilder.EnableSensitiveDataLogging(); + //} + protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); - ChampionEntity corichard = new ChampionEntity() {Name="Corichard", Bio="biobiobiobio", Icon="/a/a/a/a"}; + ChampionEntity corichard = new ChampionEntity {Name="Corichard", Bio="biobiobiobio", Icon="/a/a/a/a"}; ChampionEntity pintrand = new ChampionEntity { Name = "Pintrand", Bio = "mimimimimim", Icon = "/small.png" }; + //ChampionEntity corichard = new ChampionEntity() { Name = "Corichard", Bio = "biobiobiobio", Icon = "/a/a/a/a", Image = new LargeImageEntity { Base64 = "base" } }; + //ChampionEntity pintrand = new ChampionEntity { Name = "Pintrand", Bio = "mimimimimim", Icon = "/small.png", Image = new LargeImageEntity { Base64 = "base" } }; + modelBuilder.Entity().HasData(corichard, pintrand); - modelBuilder.Entity().HasData(new { Name = "aaaa", ChampionEntityForeignKey = 1, Description = "So What", Icon="/Icon.png", Price=10.0 }, - new { Name = "skin", ChampionEntityForeignKey = 1, Description = "So What", Icon = "/Icon.png", Price = 10.0 }, - new { Name = "bo", ChampionEntityForeignKey = 1, Description = "So What", Icon = "/Icon.png", Price = 10.0 }, - new { Name = "Joulie", ChampionEntityForeignKey = 1, Description = "So What", Icon = "/Icon.png", Price = 10.0 }, - new { Name = "Radiance", ChampionEntityForeignKey = 1, Description = "So What", Icon = "/Icon.png", Price = 10.0 }, - new { Name = "void", ChampionEntityForeignKey = 1, Description = "So What", Icon = "/Icon.png", Price = 10.0 }, - new { Name = "Radiance", ChampionEntityForeignKey = 2, Description = "So What", Icon = "/Icon.png", Price = 10.0 }, - new { Name = "void", ChampionEntityForeignKey = 2, Description = "So What", Icon = "/Icon.png", Price = 10.0 }, - new { Name = "DarkTheme", ChampionEntityForeignKey = 2, Description = "So What", Icon = "/Icon.png", Price = 10.0 }, - new { Name = "gold", ChampionEntityForeignKey = 2, Description = "So What", Icon = "/Icon.png", Price = 10.0 }, - new { Name = "ruby", ChampionEntityForeignKey = 2, Description = "So What", Icon = "/Icon.png", Price = 10.0 } + modelBuilder.Entity().HasData(new { Name = "aaaa", ChampionEntityForeignKey = 1, Description = "So What", Icon="/Icon.png", Price=10.0f }, + new { Name = "skin", ChampionEntityForeignKey = 1, Description = "So What", Icon = "/Icon.png", Price = 10.0f }, + new { Name = "bo", ChampionEntityForeignKey = 1, Description = "So What", Icon = "/Icon.png", Price = 10.0f }, + new { Name = "Joulie", ChampionEntityForeignKey = 1, Description = "So What", Icon = "/Icon.png", Price = 10.0f }, + new { Name = "Radiance", ChampionEntityForeignKey = 1, Description = "So What", Icon = "/Icon.png", Price = 10.0f }, + new { Name = "void", ChampionEntityForeignKey = 1, Description = "So What", Icon = "/Icon.png", Price = 10.0f }, + new { Name = "Radiance", ChampionEntityForeignKey = 2, Description = "So What", Icon = "/Icon.png", Price = 10.0f }, + new { Name = "void", ChampionEntityForeignKey = 2, Description = "So What", Icon = "/Icon.png", Price = 10.0f }, + new { Name = "DarkTheme", ChampionEntityForeignKey = 2, Description = "So What", Icon = "/Icon.png", Price = 10.0f }, + new { Name = "gold", ChampionEntityForeignKey = 2, Description = "So What", Icon = "/Icon.png", Price = 10.0f }, + new { Name = "ruby", ChampionEntityForeignKey = 2, Description = "So What", Icon = "/Icon.png", Price = 10.0f } ); } diff --git a/Sources/EntityFramework/champion.db b/Sources/EntityFramework/champion.db index 662e97286ee8cfaef248c402272a5a70116a24d4..95e56f32d634a0b28a3fe1742eb2c2daa9a8eee9 100644 GIT binary patch delta 266 zcmZo@U}|V!njkI6%)r3F0mLAh4T#w%>KIEiGwAu(^74LTVB}rGz`KNZ3HNRo+$<>I z$j!ociSgy+{oI8hM#*Lqol4td zhx`)*xFq=)oih@13o`TbSa^Zj!Ft~D-{L<8)Uktq^09b3F0j}){@45ufVwX6PkxZE S0ulSo|CRqe*rdtt>jeQy&_d_{ delta 251 zcmZo@U}|V!njkI6#K6G70mLxCGEv7^nu$R#UW%9h2Ln6zZU(+f{A+o?@h;&p;H~7| zy;)Gek(;HMon3tLe(pk+CO200%_cmD7+D%4nb{}*;=RGr7{SQC`5K=dBO4?CO$Pp( zn*|-t^H07hug=8