From 22ed13d5351e7321d03ccfaa9d8af016612dd636 Mon Sep 17 00:00:00 2001 From: "arthur.valin" Date: Sat, 4 Feb 2023 11:06:02 +0100 Subject: [PATCH] Better Project Structure --- .vs/League-of-Legends_Project3/v17/.wsuo | Bin 0 -> 14336 bytes .../Sources/Entities/ChampionDbContext.cs | 29 +++++++++ .../Sources/Entities/ChampionEntity.cs | 15 +++++ .../Sources/Entities/Entities.Champions.db | Bin 0 -> 20480 bytes .../Entities/Entities.Champions.db-shm | Bin 0 -> 32768 bytes .../Entities/Entities.Champions.db-wal | Bin 0 -> 82432 bytes .../Sources/Entities/Entities.csproj | 24 ++++++++ ...0230204100209_myFirstMigration.Designer.cs | 55 ++++++++++++++++++ .../20230204100209_myFirstMigration.cs | 45 ++++++++++++++ .../ChampionDbContextModelSnapshot.cs | 52 +++++++++++++++++ .../Sources/Entities/Program.cs | 14 +++++ .../EntityFramework/EntityFramework.csproj | 2 +- .../Sources/LeagueOfLegends.sln | 13 +++-- EntityFramework_LoL/Sources/Stub/Program.cs | 15 +++++ EntityFramework_LoL/Sources/Stub/Stub.csproj | 15 +++++ 15 files changed, 273 insertions(+), 6 deletions(-) create mode 100644 .vs/League-of-Legends_Project3/v17/.wsuo create mode 100644 EntityFramework_LoL/Sources/Entities/ChampionDbContext.cs create mode 100644 EntityFramework_LoL/Sources/Entities/ChampionEntity.cs create mode 100644 EntityFramework_LoL/Sources/Entities/Entities.Champions.db create mode 100644 EntityFramework_LoL/Sources/Entities/Entities.Champions.db-shm create mode 100644 EntityFramework_LoL/Sources/Entities/Entities.Champions.db-wal create mode 100644 EntityFramework_LoL/Sources/Entities/Entities.csproj create mode 100644 EntityFramework_LoL/Sources/Entities/Migrations/20230204100209_myFirstMigration.Designer.cs create mode 100644 EntityFramework_LoL/Sources/Entities/Migrations/20230204100209_myFirstMigration.cs create mode 100644 EntityFramework_LoL/Sources/Entities/Migrations/ChampionDbContextModelSnapshot.cs create mode 100644 EntityFramework_LoL/Sources/Entities/Program.cs create mode 100644 EntityFramework_LoL/Sources/Stub/Program.cs create mode 100644 EntityFramework_LoL/Sources/Stub/Stub.csproj diff --git a/.vs/League-of-Legends_Project3/v17/.wsuo b/.vs/League-of-Legends_Project3/v17/.wsuo new file mode 100644 index 0000000000000000000000000000000000000000..5e22404fe5fe2e1d66d4552f005e77589fd4dd91 GIT binary patch literal 14336 zcmeHN%X1V(81H}}C_WHHMbr=@qO!@pNH(idgglh0L?W9I4qKI)%ubReyE|Ju8)A4^ zdh+kE%8NI>>Ol|O;mXC*D(~JbE)svgndxlLK4)h`Ah^BNJN^E;zyA8`Uw_?q?;QT) zyPuBzDXQFAu~$6UJSg@n={-tVyePy$#F_SBb90kf3?tZeyNCmqgo$5S^oj{lz_%ne zIF-KLQL%4p&iAyab=RD_c|CEj=Mc*M_MB6A1{6(kRa^k|C4?r#mn~ZHW*-%Mw&;`X z-rV}JAtXb5ZFfcFMNZ5JP3U43|I5M<7ex`A$f7p|VY%fRefq^7dpysefM5EjQT7{m zG0E|B+(q=n1V0S;6ndb+8;uCN>7d{C_>Z9Os$2hMeE+SI*VmDzCUJe!9Ys2)?RoeY z;K{?o@WmDx-?Bx3Y@kC|)fBgv8{~5?*cm0D2a8eqj z9^l&Lp8qub0eG%ymSOs<2-jQxFCks(2(EvYr;|F-iFN-UM-Fh_{Ce)&)n%#wWg2Bj zhWV9xUrl=xW!{2+8@?C*1biR-JMjJR@4}yie-Hi?{QK}9z<&tOc0%|Lzz@QQ;Un-- zc$EgjUFVMj#2rK#C14#5_+t{dCx^HNOynRl1IVZ>#%wgil0=CWRFnk%;r`EgB}IH% zI?j(QG>&$4u?7_8v^)>`1(8AOI(lG&QWo?YW3g}m{6jtVmD_<7Xyia&(s0JP1d7W@ zE!h~%p)Pyu{hr47xdtTO@#fZ#5l2yW=`M;zpxtY45ij;Xs zdLq36=AZi&brsz>=&1D1qYno9unIJ8f+JpOcj~DBr$C?W5$F0HKe5M6w~=c4T#q_> z;P(V_68x8Q@0UKYJNI_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ff --git a/EntityFramework_LoL/Sources/Entities/ChampionDbContext.cs b/EntityFramework_LoL/Sources/Entities/ChampionDbContext.cs new file mode 100644 index 0000000..d7f3cd0 --- /dev/null +++ b/EntityFramework_LoL/Sources/Entities/ChampionDbContext.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore; + +namespace Entities +{ + public class ChampionDbContext : DbContext + { + public DbSet champions { get; set; } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseSqlite($"Data Source=Entities.Champions.db"); + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().HasData(new List() { + new ChampionEntity + { + Name = "Dave", + Bio = "Le meilleur Jazzman de France", + }, + new ChampionEntity + { + Name = "Armure", + Bio = "Solide", + } + }); + } + } +} diff --git a/EntityFramework_LoL/Sources/Entities/ChampionEntity.cs b/EntityFramework_LoL/Sources/Entities/ChampionEntity.cs new file mode 100644 index 0000000..27499d9 --- /dev/null +++ b/EntityFramework_LoL/Sources/Entities/ChampionEntity.cs @@ -0,0 +1,15 @@ +using System.ComponentModel.DataAnnotations; +namespace Entities +{ + public class ChampionEntity + { + [Key] + [MaxLength(256)] + public string? Name { get; set; } + [Required] + [MaxLength(500)] + public string Bio { get; set; } + public string? Icon { get; set; } + + } +} diff --git a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db new file mode 100644 index 0000000000000000000000000000000000000000..2643996e4069079cab2a9c289dd5eca80da0fc2f GIT binary patch literal 20480 zcmeI&zi!h&9Ki9jleQ4a4HK5ikdr5nP-MrTtfZ9@R?{S;2DJmSOk%)N6H~{PU~FH6 zC*Wmx1t!!NVB}npv{=r@((3z@Prf_bcm93s#eWW8_me!9AJS|V<8)~iHsIRN)q8;uS&EKMKT#D@<&F{wL_P2FA(~kfG2q1s}0tg_000Iag z@LvSZo!XY!YH1fv9=$(_C!eC(=OmpkR+akR*y{zJ40^kLPg<*fOFlLlQiU~$X0as$ z?**A+GI4I zIQ31_YiS~xPvb9((-ZZq8b)V%dey$3D|A-VZk!)!TV}VbT@0_%3`6hbLGm$+@*>w) z$s$j)ua%wpzv)-*b4{@t)1Q`3yDYM1pbDK)mQK$m`P(>KsFN)Xt2BIl(|p%mr%^di z=u~#s)E#xNxT_3RwB}Et76JhT5I_I{1Q0*~0R#|0009JUufQX%=9(S5SP**gxE=3=>lCx(hV)kKDEd z7KuQNL=uBMs4>nE6B8d0<-r%hkobT^5`9>V;RPQckq`pYV5SdhJm+pL-Le89o2>dh zY42@s@6J8vlkK6uo!{@ayjFf#X}t27qEsug`MOuW6|9a2`k(As-_u21ie(#to4!ZO|6!D-TfB*srAbiBzS&4G9=o73Oe%c5IN@kSMo2s)@$!%Ee#eyZw3)rq2K^8o?~ zAb1Jz2TnLwyv;Izok7=@KalQ+B#c% zwi)fgZO@E%ur8LG^z*q-+M=oCq>nsvmx(b4f(umpPMrRf=iH&l_t`cuY1orR zigYxE&K5g0kd0KU0I|L9w009ILKmY**5I_I{1WHEW!Se{dE?cu^)1})ojX*Z}zyHFu z0M0=+2q1s}0tg_000IagfB*srAW+%@#qtQwUc0ute9eU$cgZ7=aRQk~kZbaNVeH_3 z@(A3DH&Q3_2;80#Cy&50LLNa5lsy6nAbRIRU!{z7#0R#|0009IL zKmY**5I_I{1Rl0P(Yk|=rUtL}KCa)T?w}J#5aXA7S(`xa3u6cOQ+KdT@kSL{cTlYw zcIpmRouKZZaHJuC00IagfB*srAb zpcx1P2q1s}0tg_000IagfB*srJh(uyJc8S1N5mcZweBu?1m)tYGM12Q@_k|K;C}K5 z$`x;=o; zW;TyN)(FVor!baYJ@4sn&MlUC1e$(a(XZ-f#Eyml0tg_000IagfB*srAb3{s-E`3J^ELTaL=yW$F*}{-YIn_oE=9T1b6uwGzC!?QnxPdzt0R$t(xvtB?yS^86F1_&U4 z00IagfB*srAb + + + net6.0 + enable + enable + $(MSBuildProjectDirectory) + Exe + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/EntityFramework_LoL/Sources/Entities/Migrations/20230204100209_myFirstMigration.Designer.cs b/EntityFramework_LoL/Sources/Entities/Migrations/20230204100209_myFirstMigration.Designer.cs new file mode 100644 index 0000000..b71d075 --- /dev/null +++ b/EntityFramework_LoL/Sources/Entities/Migrations/20230204100209_myFirstMigration.Designer.cs @@ -0,0 +1,55 @@ +// +using Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Entities.Migrations +{ + [DbContext(typeof(ChampionDbContext))] + [Migration("20230204100209_myFirstMigration")] + partial class myFirstMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("Entities.ChampionEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("Bio") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Icon") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("champions"); + + b.HasData( + new + { + Name = "Dave", + Bio = "Le meilleur Jazzman de France" + }, + new + { + Name = "Armure", + Bio = "Solide" + }); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/EntityFramework_LoL/Sources/Entities/Migrations/20230204100209_myFirstMigration.cs b/EntityFramework_LoL/Sources/Entities/Migrations/20230204100209_myFirstMigration.cs new file mode 100644 index 0000000..30af7dd --- /dev/null +++ b/EntityFramework_LoL/Sources/Entities/Migrations/20230204100209_myFirstMigration.cs @@ -0,0 +1,45 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace Entities.Migrations +{ + /// + public partial class myFirstMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "champions", + columns: table => new + { + Name = table.Column(type: "TEXT", maxLength: 256, nullable: false), + Bio = table.Column(type: "TEXT", maxLength: 500, nullable: false), + Icon = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_champions", x => x.Name); + }); + + migrationBuilder.InsertData( + table: "champions", + columns: new[] { "Name", "Bio", "Icon" }, + values: new object[,] + { + { "Armure", "Solide", null }, + { "Dave", "Le meilleur Jazzman de France", null } + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "champions"); + } + } +} diff --git a/EntityFramework_LoL/Sources/Entities/Migrations/ChampionDbContextModelSnapshot.cs b/EntityFramework_LoL/Sources/Entities/Migrations/ChampionDbContextModelSnapshot.cs new file mode 100644 index 0000000..3595433 --- /dev/null +++ b/EntityFramework_LoL/Sources/Entities/Migrations/ChampionDbContextModelSnapshot.cs @@ -0,0 +1,52 @@ +// +using Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Entities.Migrations +{ + [DbContext(typeof(ChampionDbContext))] + partial class ChampionDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("Entities.ChampionEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("Bio") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Icon") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("champions"); + + b.HasData( + new + { + Name = "Dave", + Bio = "Le meilleur Jazzman de France" + }, + new + { + Name = "Armure", + Bio = "Solide" + }); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/EntityFramework_LoL/Sources/Entities/Program.cs b/EntityFramework_LoL/Sources/Entities/Program.cs new file mode 100644 index 0000000..2acf068 --- /dev/null +++ b/EntityFramework_LoL/Sources/Entities/Program.cs @@ -0,0 +1,14 @@ +using Entities; + +ChampionEntity dave = new() +{ + Name = "Imri Cartel", + Bio = "Fou Furieux", +}; +using (var context = new ChampionDbContext()) +{ + // Crée des nounours et les insère dans la base + Console.WriteLine("Creates and inserts new Champion"); + context.Add(dave); + context.SaveChanges(); +} diff --git a/EntityFramework_LoL/Sources/EntityFramework/EntityFramework.csproj b/EntityFramework_LoL/Sources/EntityFramework/EntityFramework.csproj index 06df015..95f8b96 100644 --- a/EntityFramework_LoL/Sources/EntityFramework/EntityFramework.csproj +++ b/EntityFramework_LoL/Sources/EntityFramework/EntityFramework.csproj @@ -5,7 +5,7 @@ net6.0 enable enable - $(MSBuildProjectDirectory) + $(MSBuildProjectDirectory) diff --git a/EntityFramework_LoL/Sources/LeagueOfLegends.sln b/EntityFramework_LoL/Sources/LeagueOfLegends.sln index da2dfc5..5e32aeb 100644 --- a/EntityFramework_LoL/Sources/LeagueOfLegends.sln +++ b/EntityFramework_LoL/Sources/LeagueOfLegends.sln @@ -19,7 +19,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API_LoL_Project", "API_LoL_ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{7F6A519E-98F8-429E-B34F-9B0D20075CFB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFramework", "EntityFramework\EntityFramework.csproj", "{59CC9D86-8D5A-4D38-B0F3-99B4073C7885}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Entity Framework", "Entity Framework", "{BC2FFCA4-3801-433F-A83E-B55345F3B31E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entities", "Entities\Entities.csproj", "{C463E2E1-237A-4339-A4C4-6EA3BE7002AE}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -51,10 +53,10 @@ Global {7F6A519E-98F8-429E-B34F-9B0D20075CFB}.Debug|Any CPU.Build.0 = Debug|Any CPU {7F6A519E-98F8-429E-B34F-9B0D20075CFB}.Release|Any CPU.ActiveCfg = Release|Any CPU {7F6A519E-98F8-429E-B34F-9B0D20075CFB}.Release|Any CPU.Build.0 = Release|Any CPU - {59CC9D86-8D5A-4D38-B0F3-99B4073C7885}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {59CC9D86-8D5A-4D38-B0F3-99B4073C7885}.Debug|Any CPU.Build.0 = Debug|Any CPU - {59CC9D86-8D5A-4D38-B0F3-99B4073C7885}.Release|Any CPU.ActiveCfg = Release|Any CPU - {59CC9D86-8D5A-4D38-B0F3-99B4073C7885}.Release|Any CPU.Build.0 = Release|Any CPU + {C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -62,6 +64,7 @@ Global GlobalSection(NestedProjects) = preSolution {1889FA6E-B7C6-416E-8628-9449FB9070B9} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {2C607793-B163-4731-A4D1-AFE8A7C4C170} + {C463E2E1-237A-4339-A4C4-6EA3BE7002AE} = {BC2FFCA4-3801-433F-A83E-B55345F3B31E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9} diff --git a/EntityFramework_LoL/Sources/Stub/Program.cs b/EntityFramework_LoL/Sources/Stub/Program.cs new file mode 100644 index 0000000..9c2e3c3 --- /dev/null +++ b/EntityFramework_LoL/Sources/Stub/Program.cs @@ -0,0 +1,15 @@ +using Entities; + +ChampionEntity dave = new() +{ + Name = "Dave", + Bio = "Le meilleur Jazzman de France", + Icon = "aaa" +}; +using (var context = new ChampionDbContext()) +{ + // Crée des nounours et les insère dans la base + Console.WriteLine("Creates and inserts new Champion"); + context.Add(dave); + context.SaveChanges(); +} diff --git a/EntityFramework_LoL/Sources/Stub/Stub.csproj b/EntityFramework_LoL/Sources/Stub/Stub.csproj new file mode 100644 index 0000000..36bc2be --- /dev/null +++ b/EntityFramework_LoL/Sources/Stub/Stub.csproj @@ -0,0 +1,15 @@ + + + + Exe + net6.0 + enable + enable + $(MSBuildProjectDirectory) + + + + + + +