From aa57c35e5fc2303843fa08e1c0dd029d312c0c73 Mon Sep 17 00:00:00 2001 From: Jolys Enzo Date: Wed, 8 Feb 2023 15:23:01 +0100 Subject: [PATCH] one to many skins fini --- Sources/Api-lol/Controllers/Skins.cs | 4 +- Sources/Client/Program.cs | 13 +-- Sources/Client/StubEntityInit.cs | 61 ++++++++++ Sources/EntityFramwork/BDD-APILOL.db | Bin 28672 -> 40960 bytes Sources/EntityFramwork/BDD-APILOL.db-shm | Bin 0 -> 32768 bytes Sources/EntityFramwork/BDD-APILOL.db-wal | 0 Sources/EntityFramwork/BDDContext.cs | 34 ++++-- Sources/EntityFramwork/EntityChampions.cs | 2 + Sources/EntityFramwork/EntityFramwork.csproj | 4 - Sources/EntityFramwork/EntityLargeImage.cs | 7 +- Sources/EntityFramwork/EntitySkins.cs | 3 + Sources/EntityFramwork/Factories/Factories.cs | 13 +-- ...ner.cs => 20230208121743_test.Designer.cs} | 22 +++- ...20_testMigra.cs => 20230208121743_test.cs} | 24 +++- .../20230208121840_test2.Designer.cs | 108 ++++++++++++++++++ .../Migrations/20230208121840_test2.cs | 22 ++++ .../20230208135031_test3.Designer.cs | 108 ++++++++++++++++++ .../Migrations/20230208135031_test3.cs | 62 ++++++++++ .../Migrations/BDDContextModelSnapshot.cs | 24 +++- 19 files changed, 470 insertions(+), 41 deletions(-) create mode 100644 Sources/Client/StubEntityInit.cs create mode 100644 Sources/EntityFramwork/BDD-APILOL.db-shm create mode 100644 Sources/EntityFramwork/BDD-APILOL.db-wal rename Sources/EntityFramwork/Migrations/{20230206102420_testMigra.Designer.cs => 20230208121743_test.Designer.cs} (81%) rename Sources/EntityFramwork/Migrations/{20230206102420_testMigra.cs => 20230208121743_test.cs} (74%) create mode 100644 Sources/EntityFramwork/Migrations/20230208121840_test2.Designer.cs create mode 100644 Sources/EntityFramwork/Migrations/20230208121840_test2.cs create mode 100644 Sources/EntityFramwork/Migrations/20230208135031_test3.Designer.cs create mode 100644 Sources/EntityFramwork/Migrations/20230208135031_test3.cs diff --git a/Sources/Api-lol/Controllers/Skins.cs b/Sources/Api-lol/Controllers/Skins.cs index 0d1d7cb..55152ce 100644 --- a/Sources/Api-lol/Controllers/Skins.cs +++ b/Sources/Api-lol/Controllers/Skins.cs @@ -24,9 +24,9 @@ namespace Api_lol.Controllers [HttpGet] public async Task Get() { - var champs = (await data.SkinsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Select(Model => Model.ModelToDto()); + var skins = (await data.SkinsMgr.GetItems(0, await data.SkinsMgr.GetNbItems())).Select(Model => Model.ModelToDto()); - return Ok(champs); + return Ok(skins); } [HttpGet] diff --git a/Sources/Client/Program.cs b/Sources/Client/Program.cs index eed9cc0..28c9b3e 100644 --- a/Sources/Client/Program.cs +++ b/Sources/Client/Program.cs @@ -1,6 +1,7 @@ // See https://aka.ms/new-console-template for more information +using Api_lol.Factories; using Client; using DTO; using EntityFramwork; @@ -10,16 +11,8 @@ using StubLib; StubData tmp = new StubData(); -var tmpListe = await tmp.ChampionsMgr.GetItemsByName("Akali", 0, 6); -Champion champ = tmpListe.First(); -Factories facto = new Factories(); - - -using ( BDDContext db = new BDDContext()) -{ - - db.SaveChanges(); -} +StubEntityInit dbStub = new StubEntityInit(); +dbStub.Init(); /* Console.WriteLine("Start"); diff --git a/Sources/Client/StubEntityInit.cs b/Sources/Client/StubEntityInit.cs new file mode 100644 index 0000000..874ff27 --- /dev/null +++ b/Sources/Client/StubEntityInit.cs @@ -0,0 +1,61 @@ +using DTO; +using EntityFramwork.Factories; +using EntityFramwork; +using Model; +using StubLib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Api_lol.Factories; + +namespace Client +{ + public class StubEntityInit + { + private Factories facto = new Factories(); + + + public async void AddAllChampions() + { + StubData data = new StubData(); + var liste = await data.ChampionsMgr.GetItems(0,await data.ChampionsMgr.GetNbItems()); + var listeDto = liste.ToList().Select(model => facto.ChampionModelToEntity(model)); + + using (BDDContext db = new BDDContext()) + { + foreach(var item in listeDto) + { + db.Add(item); + } + db.SaveChanges(); + } + } + + public async void AddAllSkins() + { + StubData data = new StubData(); + var skins = await data.SkinsMgr.GetItems(0, await data.SkinsMgr.GetNbItems()); + //var skinsDto = skins.ToList().Select(model => facto.SkinsModelToEntity(model)); + + using (BDDContext db = new BDDContext()) + { + foreach (var item in skins) + { + int idChampion = (db.Champions.Where(m => m.Name == item.Champion.Name).First()).Id; + EntitySkins skin = facto.SkinsModelToEntity(item,idChampion); + db.Add(skin); + } + db.SaveChanges(); + } + } + + + public void Init() + { + AddAllChampions(); + AddAllSkins(); + } + } +} diff --git a/Sources/EntityFramwork/BDD-APILOL.db b/Sources/EntityFramwork/BDD-APILOL.db index 4d1ae4c017172db3ae19a2fa3755eefd33596f2c..e5854ee68ea46789a83b72d9b46869d5786ffa70 100644 GIT binary patch literal 40960 zcmeI)UuYaf90&0IbGv(ga{V=EU1JMbkGAR2Qj@#Z^hNM;+0>)SCB0lEMdVnMZF)Aj zYi}>uf-h;Q2o^!4_@*L)C00Izzz-=QCIjcTr z4h_jq8CB=8W!F7isJbi13bRLxC9iEIoX**)ylv%EW0STOYfFn+JECEWO|i^k%*tf* z_I^8OWvBC2c5ZUgN>68J^SKn;ZpCH})XI)oGr7!EDtE{_U>~wlbNT5^mK|Zr&gOU3 z%Ss<{R*n_RrHOLIEiRP~xF@eH+s`}hdJC1}u`0_Rv-0*lJ97Q#evZt-Rg-2a#RWHJ zvHDGR?$&zh6ZKOs_$THyVy&k*F`ctB`?I26J7Rv`mKh2c;u}7t7)3@nI+LoqIpDMv^R^`*1I`aQ7`cpKl4Pb#ZUKz z3{iA#y;*cei(f<0XzBLudOaM%53!CMkLTyP6Lf!5C6qYrBU29+*rf_=zfnn4_cescBKWLcyMxDlSzVek1Z8Dtgs&?i4BlYHWR;y*PUg&z9!bsQ6D*J0H$p50^ zAL>d*Wi{E{H!(80Cn-`zBL9J3rS~NIg}z`5Ob~zo z1Rwwb2tWV=5P$##AOHaf{C@=QR`<%?z79~^5?a0qQ0`Kbp~fD~F9G=P|2o|%(YN$A zJwprh09(NX0SG_<0uX=z1Rwwb2tWV=5V#ElhICEZJQPnYvxfzo3VZ&*Dwf!zYNb`{ zUjE2hb8V}pNt=e^V@_qUN3QJwO&Vau9rcblr5^dVs-m>ikxH>guI);#G^biApXiZq zo2*GDKdQ6btGForB`I`4q6_rXZP2u+A_O1+0SG_<0uX=z1Rwwb2teSL69~zwDT`NM z^hXtSP;R`CL1$GBheQhh{hz(`4-*6+009U<00Izz00bZa0SG_<0=KXLfBwIpUX(5oy9CI~sz7!_e34+9YqhIy!lL>LsI!9ztCp(esWKxO|Izyn29Lm~e8U#IgD z`{aL-eFN|fou|)lN>xxO1Rwwb2tWV=5P$##AOHafKmYK zh1CJM_Qrt#-^O1mpo(qcy#Y#4HACXn04)bLTH=U800Izz00bZa0SG_<0uX=z1R!t= z3GnCt`{{9sF46DwGks5A)2H+iy-)AZ>+~|cK+n<{dXhYr1rr1y009U<00Izz00bZa z0SG_<0_zGG{kkMaqe0!+=tszpY^X&vBkD)`{79r02^e8N5~@X1Bj`sAKcd$nilOm) delta 238 zcmZoTz|`=7ae_QAI|Bl+Ow_Ry=KsOK#(jc;?-Ku7-Y>k1c(l1sY!(y<;O0zZV;46T zXKZAhJdsC?$unj0MjllV^?*m5!!t!mv#ErYeewiuQAW1O>p3$g^Yc_rp2?*JQgN0` z0z|#%GTpq0H;IXjk^de8|GmwE0ay5S6d0Lp#f=P%j17zo%nS{TOpFZTOHzwVd^6LF y63z7t^o+QG4rJti!odFosN)vDj5M().HasKey(a => a.Id); modelBuilder.Entity().Property(a => a.Id) - .ValueGeneratedOnAdd(); - + .ValueGeneratedOnAdd(); + modelBuilder.Entity().HasIndex(a => a.Name) + .IsUnique(true); + //Clé avec skins + modelBuilder.Entity() + .HasMany(e => e.Skins) + .WithOne(e => e.Champion) + .HasForeignKey(e => e.ChampionForeignKey); + //Clé avec Images + modelBuilder.Entity().HasOne(n => n.Image) + .WithOne(c => c.Champion) + .HasForeignKey(c => c.Champion); + // -------------------------------------------------------------------------------// //création de la table Skins modelBuilder.Entity().HasKey(m => m.Id); modelBuilder.Entity().Property(m => m.Id) .ValueGeneratedOnAdd(); - //modelBuilder.Entity().Property("ChampionForeignKey"); - // Use the shadow property as a foreign key - /* - modelBuilder.Entity() - .HasOne(m => m.Champion) - .WithMany(a => a.Skins) - .HasForeignKey("ChampionsForeignKey");*/ + modelBuilder.Entity() + .HasMany(e => e.Skins) + .WithOne(e => e.Champion) + .HasForeignKey(e => e.ChampionForeignKey); + + // -------------------------------------------------------------------------------// + //création de la table Images + modelBuilder.Entity().HasKey(c => c.Id); + modelBuilder.Entity().Property(c => c.Id) + .ValueGeneratedOnAdd(); + + } public DbSet Champions { get; set; } diff --git a/Sources/EntityFramwork/EntityChampions.cs b/Sources/EntityFramwork/EntityChampions.cs index 8b878ad..3c8285a 100644 --- a/Sources/EntityFramwork/EntityChampions.cs +++ b/Sources/EntityFramwork/EntityChampions.cs @@ -20,5 +20,7 @@ namespace DTO public List Skins { get; set; } + public EntityLargeImage Image { get; set; } + } } diff --git a/Sources/EntityFramwork/EntityFramwork.csproj b/Sources/EntityFramwork/EntityFramwork.csproj index b4abec4..0275498 100644 --- a/Sources/EntityFramwork/EntityFramwork.csproj +++ b/Sources/EntityFramwork/EntityFramwork.csproj @@ -21,8 +21,4 @@ - - - - diff --git a/Sources/EntityFramwork/EntityLargeImage.cs b/Sources/EntityFramwork/EntityLargeImage.cs index a5f291c..cf892b8 100644 --- a/Sources/EntityFramwork/EntityLargeImage.cs +++ b/Sources/EntityFramwork/EntityLargeImage.cs @@ -1,4 +1,5 @@ -using System; +using DTO; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,8 +9,10 @@ namespace EntityFramwork { public class EntityLargeImage { - public long Id { get; set; } + public int Id { get; set; } public string Base64 { get; set; } + + public EntityChampions Champion { get; set; } } } diff --git a/Sources/EntityFramwork/EntitySkins.cs b/Sources/EntityFramwork/EntitySkins.cs index c956415..c72d4ff 100644 --- a/Sources/EntityFramwork/EntitySkins.cs +++ b/Sources/EntityFramwork/EntitySkins.cs @@ -2,6 +2,7 @@ using Model; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; @@ -18,6 +19,8 @@ namespace EntityFramwork public float Price { get; set; } + public int ChampionForeignKey { get; set; } + [ForeignKey("ChampionForeignKey")] public EntityChampions Champion { get; set; } } diff --git a/Sources/EntityFramwork/Factories/Factories.cs b/Sources/EntityFramwork/Factories/Factories.cs index 6c9f980..557c405 100644 --- a/Sources/EntityFramwork/Factories/Factories.cs +++ b/Sources/EntityFramwork/Factories/Factories.cs @@ -5,29 +5,26 @@ namespace EntityFramwork.Factories { public class Factories { - public EntityChampions ChampionModelToEntity(Champion champ,int sansSkin = 0) + public EntityChampions ChampionModelToEntity(Champion champ) { EntityChampions entity = new EntityChampions(); entity.Name = champ.Name; entity.Bio = champ.Bio; entity.Icon = champ.Icon; - if ( sansSkin == 0) - { - //entity.Skins = champ.Skins.Select(Model => this.SkinsModelToEntity(Model)).ToList(); - } return entity; } - public EntitySkins SkinsModelToEntity(Skin skin) + public EntitySkins SkinsModelToEntity(Skin skin,int id) { EntitySkins entity= new EntitySkins(); entity.Price = skin.Price; entity.Icon = skin.Icon; - entity.Description= skin.Description; - //entity.Champion = ChampionModelToEntity(skin.Champion,1); + entity.Description = skin.Description; + entity.ChampionForeignKey = id; + //entity.Champion = ChampionModelToEntity(skin.Champion); return entity; } diff --git a/Sources/EntityFramwork/Migrations/20230206102420_testMigra.Designer.cs b/Sources/EntityFramwork/Migrations/20230208121743_test.Designer.cs similarity index 81% rename from Sources/EntityFramwork/Migrations/20230206102420_testMigra.Designer.cs rename to Sources/EntityFramwork/Migrations/20230208121743_test.Designer.cs index 4831a4b..60e5442 100644 --- a/Sources/EntityFramwork/Migrations/20230206102420_testMigra.Designer.cs +++ b/Sources/EntityFramwork/Migrations/20230208121743_test.Designer.cs @@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace EntityFramwork.Migrations { [DbContext(typeof(BDDContext))] - [Migration("20230206102420_testMigra")] - partial class testMigra + [Migration("20230208121743_test")] + partial class test { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -39,9 +39,27 @@ namespace EntityFramwork.Migrations b.HasKey("Id"); + b.HasIndex("Name") + .IsUnique(); + b.ToTable("Champions"); }); + modelBuilder.Entity("EntityFramwork.EntityLargeImage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Base64") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Images"); + }); + modelBuilder.Entity("EntityFramwork.EntitySkins", b => { b.Property("Id") diff --git a/Sources/EntityFramwork/Migrations/20230206102420_testMigra.cs b/Sources/EntityFramwork/Migrations/20230208121743_test.cs similarity index 74% rename from Sources/EntityFramwork/Migrations/20230206102420_testMigra.cs rename to Sources/EntityFramwork/Migrations/20230208121743_test.cs index f21f03f..2a337a8 100644 --- a/Sources/EntityFramwork/Migrations/20230206102420_testMigra.cs +++ b/Sources/EntityFramwork/Migrations/20230208121743_test.cs @@ -5,7 +5,7 @@ namespace EntityFramwork.Migrations { /// - public partial class testMigra : Migration + public partial class test : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -25,6 +25,19 @@ namespace EntityFramwork.Migrations table.PrimaryKey("PK_Champions", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Images", + 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_Images", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Skins", columns: table => new @@ -47,6 +60,12 @@ namespace EntityFramwork.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateIndex( + name: "IX_Champions_Name", + table: "Champions", + column: "Name", + unique: true); + migrationBuilder.CreateIndex( name: "IX_Skins_ChampionId", table: "Skins", @@ -56,6 +75,9 @@ namespace EntityFramwork.Migrations /// protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropTable( + name: "Images"); + migrationBuilder.DropTable( name: "Skins"); diff --git a/Sources/EntityFramwork/Migrations/20230208121840_test2.Designer.cs b/Sources/EntityFramwork/Migrations/20230208121840_test2.Designer.cs new file mode 100644 index 0000000..70c622a --- /dev/null +++ b/Sources/EntityFramwork/Migrations/20230208121840_test2.Designer.cs @@ -0,0 +1,108 @@ +// +using EntityFramwork; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EntityFramwork.Migrations +{ + [DbContext(typeof(BDDContext))] + [Migration("20230208121840_test2")] + partial class test2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("DTO.EntityChampions", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Bio") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("Champions"); + }); + + modelBuilder.Entity("EntityFramwork.EntityLargeImage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Base64") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Images"); + }); + + modelBuilder.Entity("EntityFramwork.EntitySkins", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ChampionId") + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Id"); + + b.HasIndex("ChampionId"); + + b.ToTable("Skins"); + }); + + modelBuilder.Entity("EntityFramwork.EntitySkins", b => + { + b.HasOne("DTO.EntityChampions", "Champion") + .WithMany("Skins") + .HasForeignKey("ChampionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Champion"); + }); + + modelBuilder.Entity("DTO.EntityChampions", b => + { + b.Navigation("Skins"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EntityFramwork/Migrations/20230208121840_test2.cs b/Sources/EntityFramwork/Migrations/20230208121840_test2.cs new file mode 100644 index 0000000..845120e --- /dev/null +++ b/Sources/EntityFramwork/Migrations/20230208121840_test2.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EntityFramwork.Migrations +{ + /// + public partial class test2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/Sources/EntityFramwork/Migrations/20230208135031_test3.Designer.cs b/Sources/EntityFramwork/Migrations/20230208135031_test3.Designer.cs new file mode 100644 index 0000000..3e06bb3 --- /dev/null +++ b/Sources/EntityFramwork/Migrations/20230208135031_test3.Designer.cs @@ -0,0 +1,108 @@ +// +using EntityFramwork; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EntityFramwork.Migrations +{ + [DbContext(typeof(BDDContext))] + [Migration("20230208135031_test3")] + partial class test3 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("DTO.EntityChampions", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Bio") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("Champions"); + }); + + modelBuilder.Entity("EntityFramwork.EntityLargeImage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Base64") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Images"); + }); + + modelBuilder.Entity("EntityFramwork.EntitySkins", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ChampionForeignKey") + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Id"); + + b.HasIndex("ChampionForeignKey"); + + b.ToTable("Skins"); + }); + + modelBuilder.Entity("EntityFramwork.EntitySkins", b => + { + b.HasOne("DTO.EntityChampions", "Champion") + .WithMany("Skins") + .HasForeignKey("ChampionForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Champion"); + }); + + modelBuilder.Entity("DTO.EntityChampions", b => + { + b.Navigation("Skins"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EntityFramwork/Migrations/20230208135031_test3.cs b/Sources/EntityFramwork/Migrations/20230208135031_test3.cs new file mode 100644 index 0000000..7e99d9f --- /dev/null +++ b/Sources/EntityFramwork/Migrations/20230208135031_test3.cs @@ -0,0 +1,62 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EntityFramwork.Migrations +{ + /// + public partial class test3 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Skins_Champions_ChampionId", + table: "Skins"); + + migrationBuilder.RenameColumn( + name: "ChampionId", + table: "Skins", + newName: "ChampionForeignKey"); + + migrationBuilder.RenameIndex( + name: "IX_Skins_ChampionId", + table: "Skins", + newName: "IX_Skins_ChampionForeignKey"); + + migrationBuilder.AddForeignKey( + name: "FK_Skins_Champions_ChampionForeignKey", + table: "Skins", + column: "ChampionForeignKey", + principalTable: "Champions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Skins_Champions_ChampionForeignKey", + table: "Skins"); + + migrationBuilder.RenameColumn( + name: "ChampionForeignKey", + table: "Skins", + newName: "ChampionId"); + + migrationBuilder.RenameIndex( + name: "IX_Skins_ChampionForeignKey", + table: "Skins", + newName: "IX_Skins_ChampionId"); + + migrationBuilder.AddForeignKey( + name: "FK_Skins_Champions_ChampionId", + table: "Skins", + column: "ChampionId", + principalTable: "Champions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/Sources/EntityFramwork/Migrations/BDDContextModelSnapshot.cs b/Sources/EntityFramwork/Migrations/BDDContextModelSnapshot.cs index 85c3e43..8fb37ab 100644 --- a/Sources/EntityFramwork/Migrations/BDDContextModelSnapshot.cs +++ b/Sources/EntityFramwork/Migrations/BDDContextModelSnapshot.cs @@ -36,16 +36,34 @@ namespace EntityFramwork.Migrations b.HasKey("Id"); + b.HasIndex("Name") + .IsUnique(); + b.ToTable("Champions"); }); + modelBuilder.Entity("EntityFramwork.EntityLargeImage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Base64") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Images"); + }); + modelBuilder.Entity("EntityFramwork.EntitySkins", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); - b.Property("ChampionId") + b.Property("ChampionForeignKey") .HasColumnType("INTEGER"); b.Property("Description") @@ -61,7 +79,7 @@ namespace EntityFramwork.Migrations b.HasKey("Id"); - b.HasIndex("ChampionId"); + b.HasIndex("ChampionForeignKey"); b.ToTable("Skins"); }); @@ -70,7 +88,7 @@ namespace EntityFramwork.Migrations { b.HasOne("DTO.EntityChampions", "Champion") .WithMany("Skins") - .HasForeignKey("ChampionId") + .HasForeignKey("ChampionForeignKey") .OnDelete(DeleteBehavior.Cascade) .IsRequired();