From 3169158f48b593d0af3f67da73a60b53cf84e3b8 Mon Sep 17 00:00:00 2001 From: pasquizzat Date: Wed, 1 Feb 2023 10:00:14 +0100 Subject: [PATCH] =?UTF-8?q?=C3=A7a=20avance,=20j'ai=20commenc=C3=A9=20le?= =?UTF-8?q?=20truc=20au=20milieu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/BddTests/BddTests.csproj | 30 ++++++++++++++++++ Sources/BddTests/Program.cs | 26 +++++++++++++++ Sources/{Model2 => BddTests}/laBdd.db | Bin 20480 -> 20480 bytes Sources/LeagueOfLegends.sln | 29 +++++++++++++---- ...ChampionContexte.cs => ChampionContext.cs} | 6 ++-- Sources/Model2/ChampionEntity.cs | 11 +++++-- ...odel2.csproj => LibEntityFramework.csproj} | 0 ... => 20230201083944_Migration1.Designer.cs} | 14 ++++---- ...ration.cs => 20230201083944_Migration1.cs} | 10 +++--- ...hot.cs => ChampionContextModelSnapshot.cs} | 12 +++---- .../Tests/ConsoleTests/ConsoleTests.csproj | 2 +- .../LaConsolePourLaBdd.csproj | 21 ------------ Sources/Tests/LaConsolePourLaBdd/Program.cs | 21 ------------ Sources/TrucAuMilieu/Data.cs | 18 +++++++++++ Sources/TrucAuMilieu/TrucAuMilieu.csproj | 14 ++++++++ Sources/TrucAuMilieu/toEntity.cs | 13 ++++++++ 16 files changed, 154 insertions(+), 73 deletions(-) create mode 100644 Sources/BddTests/BddTests.csproj create mode 100644 Sources/BddTests/Program.cs rename Sources/{Model2 => BddTests}/laBdd.db (95%) rename Sources/Model2/{ChampionContexte.cs => ChampionContext.cs} (67%) rename Sources/Model2/{Model2.csproj => LibEntityFramework.csproj} (100%) rename Sources/Model2/Migrations/{20230126085130_myFirstMigration.Designer.cs => 20230201083944_Migration1.Designer.cs} (76%) rename Sources/Model2/Migrations/{20230126085130_myFirstMigration.cs => 20230201083944_Migration1.cs} (79%) rename Sources/Model2/Migrations/{ChampionContexteModelSnapshot.cs => ChampionContextModelSnapshot.cs} (76%) delete mode 100644 Sources/Tests/LaConsolePourLaBdd/LaConsolePourLaBdd.csproj delete mode 100644 Sources/Tests/LaConsolePourLaBdd/Program.cs create mode 100644 Sources/TrucAuMilieu/Data.cs create mode 100644 Sources/TrucAuMilieu/TrucAuMilieu.csproj create mode 100644 Sources/TrucAuMilieu/toEntity.cs diff --git a/Sources/BddTests/BddTests.csproj b/Sources/BddTests/BddTests.csproj new file mode 100644 index 0000000..da8ca3d --- /dev/null +++ b/Sources/BddTests/BddTests.csproj @@ -0,0 +1,30 @@ + + + + Exe + net6.0 + enable + enable + $(MSBuildProjectDirectory) + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + diff --git a/Sources/BddTests/Program.cs b/Sources/BddTests/Program.cs new file mode 100644 index 0000000..6170634 --- /dev/null +++ b/Sources/BddTests/Program.cs @@ -0,0 +1,26 @@ +using LibEntityFramework; +using TrucAuMilieu; + +ChampionEntity c1 = new ChampionEntity("champion1", "il est beau", "imagepng.jpeg"); + +Console.WriteLine("allo?"); + +using (var context = new ChampionContext()) +{ + context.Add(c1); + context.SaveChanges(); + + Console.WriteLine("champion ajouté"); + + List l = context.Champs.ToList(); + + foreach (var champion in l) { Console.WriteLine(champion.Name); } + +} +using (var data = new Data()) +{ + List l = data.listChampions()); + + foreach (var champion in l) { Console.WriteLine(champion.Name); } + +} \ No newline at end of file diff --git a/Sources/Model2/laBdd.db b/Sources/BddTests/laBdd.db similarity index 95% rename from Sources/Model2/laBdd.db rename to Sources/BddTests/laBdd.db index 04919bc0ad88c1b9c49c10aa0288d130ed1a8baa..3e282a678ad461e43d8bef9fd7e20111f45e88cd 100644 GIT binary patch delta 296 zcmZozz}T>WQ6@OhC$l6~AuYcsH?c&)m_dMnk&(ecL4kpRfn}nMGb78!g!Q~K&KZfh z1;r4O#W~2;F~n6N#L>yeRYA#lvNoSFqx0r?zU7RY*%Yqx>nbub+lw0+7#SNF85kN^ z7+ac{#QSEZ7bTWt=I0rj>lx@7aRH5IY!A*Wm8D@J_LwUWQ6@OhC$l6~AuYcsH?c&)m_dMniHX5ML4kpRfoYyeRY56vvNoSFWAf&BzU7Q8*BSV)Zx&QI%de%*$m}g{WME`$ zU}$7!U}0)#Y!IJY>6TekT;iLVUX)mpnV)B_XP{@qwV6@i4!@=nvo|LJ<-9;QF$ioH Oba>1^ae_D-Di;6;Q#hLd diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index 4f57c62..778c200 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -15,9 +15,20 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Stub", "Stub", "{2C607793-B EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubLib", "StubLib\StubLib.csproj", "{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model2", "Model2\Model2.csproj", "{D7FE55BA-1CEE-4C9D-B2FA-674D61F1B7A5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibEntityFramework", "Model2\LibEntityFramework.csproj", "{D7FE55BA-1CEE-4C9D-B2FA-674D61F1B7A5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaConsolePourLaBdd", "Tests\LaConsolePourLaBdd\LaConsolePourLaBdd.csproj", "{088B9AD5-9EF4-4B56-8883-202489984E27}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BddTests", "BddTests\BddTests.csproj", "{20E7E2FA-9482-4F46-AE84-97576399F882}" + ProjectSection(ProjectDependencies) = postProject + {00B54DCE-F7B5-4C3A-AC91-EF6BAB1AD36C} = {00B54DCE-F7B5-4C3A-AC91-EF6BAB1AD36C} + {2960F9BA-49DE-494D-92E3-CE5A794BA1A9} = {2960F9BA-49DE-494D-92E3-CE5A794BA1A9} + {D7FE55BA-1CEE-4C9D-B2FA-674D61F1B7A5} = {D7FE55BA-1CEE-4C9D-B2FA-674D61F1B7A5} + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrucAuMilieu", "TrucAuMilieu\TrucAuMilieu.csproj", "{00B54DCE-F7B5-4C3A-AC91-EF6BAB1AD36C}" + ProjectSection(ProjectDependencies) = postProject + {2960F9BA-49DE-494D-92E3-CE5A794BA1A9} = {2960F9BA-49DE-494D-92E3-CE5A794BA1A9} + {D7FE55BA-1CEE-4C9D-B2FA-674D61F1B7A5} = {D7FE55BA-1CEE-4C9D-B2FA-674D61F1B7A5} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -45,10 +56,14 @@ Global {D7FE55BA-1CEE-4C9D-B2FA-674D61F1B7A5}.Debug|Any CPU.Build.0 = Debug|Any CPU {D7FE55BA-1CEE-4C9D-B2FA-674D61F1B7A5}.Release|Any CPU.ActiveCfg = Release|Any CPU {D7FE55BA-1CEE-4C9D-B2FA-674D61F1B7A5}.Release|Any CPU.Build.0 = Release|Any CPU - {088B9AD5-9EF4-4B56-8883-202489984E27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {088B9AD5-9EF4-4B56-8883-202489984E27}.Debug|Any CPU.Build.0 = Debug|Any CPU - {088B9AD5-9EF4-4B56-8883-202489984E27}.Release|Any CPU.ActiveCfg = Release|Any CPU - {088B9AD5-9EF4-4B56-8883-202489984E27}.Release|Any CPU.Build.0 = Release|Any CPU + {20E7E2FA-9482-4F46-AE84-97576399F882}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {20E7E2FA-9482-4F46-AE84-97576399F882}.Debug|Any CPU.Build.0 = Debug|Any CPU + {20E7E2FA-9482-4F46-AE84-97576399F882}.Release|Any CPU.ActiveCfg = Release|Any CPU + {20E7E2FA-9482-4F46-AE84-97576399F882}.Release|Any CPU.Build.0 = Release|Any CPU + {00B54DCE-F7B5-4C3A-AC91-EF6BAB1AD36C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {00B54DCE-F7B5-4C3A-AC91-EF6BAB1AD36C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {00B54DCE-F7B5-4C3A-AC91-EF6BAB1AD36C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {00B54DCE-F7B5-4C3A-AC91-EF6BAB1AD36C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -56,7 +71,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} - {088B9AD5-9EF4-4B56-8883-202489984E27} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} + {20E7E2FA-9482-4F46-AE84-97576399F882} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9} diff --git a/Sources/Model2/ChampionContexte.cs b/Sources/Model2/ChampionContext.cs similarity index 67% rename from Sources/Model2/ChampionContexte.cs rename to Sources/Model2/ChampionContext.cs index 06d752b..39a4cab 100644 --- a/Sources/Model2/ChampionContexte.cs +++ b/Sources/Model2/ChampionContext.cs @@ -4,11 +4,11 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; -namespace Model2 +namespace LibEntityFramework { - internal class ChampionContexte : DbContext + public class ChampionContext : DbContext { - public DbSet champs { get; set; } + public DbSet Champs { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder options) => options.UseSqlite("DataSource=laBdd.db"); diff --git a/Sources/Model2/ChampionEntity.cs b/Sources/Model2/ChampionEntity.cs index 8204768..26e1e1c 100644 --- a/Sources/Model2/ChampionEntity.cs +++ b/Sources/Model2/ChampionEntity.cs @@ -4,13 +4,20 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Model2 +namespace LibEntityFramework { - internal class ChampionEntity + public class ChampionEntity { public int Id { get; set; } public string Name { get; set; } public string Bio { get; set; } public string Icon { get; set; } + public ChampionEntity(string name, string bio, string icon) + { + Id = 0; + Name = name; + Bio = bio; + Icon = icon; + } } } diff --git a/Sources/Model2/Model2.csproj b/Sources/Model2/LibEntityFramework.csproj similarity index 100% rename from Sources/Model2/Model2.csproj rename to Sources/Model2/LibEntityFramework.csproj diff --git a/Sources/Model2/Migrations/20230126085130_myFirstMigration.Designer.cs b/Sources/Model2/Migrations/20230201083944_Migration1.Designer.cs similarity index 76% rename from Sources/Model2/Migrations/20230126085130_myFirstMigration.Designer.cs rename to Sources/Model2/Migrations/20230201083944_Migration1.Designer.cs index d5abbad..4f52fc2 100644 --- a/Sources/Model2/Migrations/20230126085130_myFirstMigration.Designer.cs +++ b/Sources/Model2/Migrations/20230201083944_Migration1.Designer.cs @@ -1,17 +1,17 @@ // +using LibEntityFramework; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Model2; #nullable disable -namespace Model2.Migrations +namespace LibEntityFramework.Migrations { - [DbContext(typeof(ChampionContexte))] - [Migration("20230126085130_myFirstMigration")] - partial class myFirstMigration + [DbContext(typeof(ChampionContext))] + [Migration("20230201083944_Migration1")] + partial class Migration1 { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -19,7 +19,7 @@ namespace Model2.Migrations #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - modelBuilder.Entity("Model2.ChampionEntity", b => + modelBuilder.Entity("LibEntityFramework.ChampionEntity", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -39,7 +39,7 @@ namespace Model2.Migrations b.HasKey("Id"); - b.ToTable("champs"); + b.ToTable("Champs"); }); #pragma warning restore 612, 618 } diff --git a/Sources/Model2/Migrations/20230126085130_myFirstMigration.cs b/Sources/Model2/Migrations/20230201083944_Migration1.cs similarity index 79% rename from Sources/Model2/Migrations/20230126085130_myFirstMigration.cs rename to Sources/Model2/Migrations/20230201083944_Migration1.cs index bf8d6fb..b4f2535 100644 --- a/Sources/Model2/Migrations/20230126085130_myFirstMigration.cs +++ b/Sources/Model2/Migrations/20230201083944_Migration1.cs @@ -2,16 +2,16 @@ #nullable disable -namespace Model2.Migrations +namespace LibEntityFramework.Migrations { /// - public partial class myFirstMigration : Migration + public partial class Migration1 : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( - name: "champs", + name: "Champs", columns: table => new { Id = table.Column(type: "INTEGER", nullable: false) @@ -22,7 +22,7 @@ namespace Model2.Migrations }, constraints: table => { - table.PrimaryKey("PK_champs", x => x.Id); + table.PrimaryKey("PK_Champs", x => x.Id); }); } @@ -30,7 +30,7 @@ namespace Model2.Migrations protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( - name: "champs"); + name: "Champs"); } } } diff --git a/Sources/Model2/Migrations/ChampionContexteModelSnapshot.cs b/Sources/Model2/Migrations/ChampionContextModelSnapshot.cs similarity index 76% rename from Sources/Model2/Migrations/ChampionContexteModelSnapshot.cs rename to Sources/Model2/Migrations/ChampionContextModelSnapshot.cs index b020600..12e9911 100644 --- a/Sources/Model2/Migrations/ChampionContexteModelSnapshot.cs +++ b/Sources/Model2/Migrations/ChampionContextModelSnapshot.cs @@ -1,22 +1,22 @@ // +using LibEntityFramework; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Model2; #nullable disable -namespace Model2.Migrations +namespace LibEntityFramework.Migrations { - [DbContext(typeof(ChampionContexte))] - partial class ChampionContexteModelSnapshot : ModelSnapshot + [DbContext(typeof(ChampionContext))] + partial class ChampionContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - modelBuilder.Entity("Model2.ChampionEntity", b => + modelBuilder.Entity("LibEntityFramework.ChampionEntity", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -36,7 +36,7 @@ namespace Model2.Migrations b.HasKey("Id"); - b.ToTable("champs"); + b.ToTable("Champs"); }); #pragma warning restore 612, 618 } diff --git a/Sources/Tests/ConsoleTests/ConsoleTests.csproj b/Sources/Tests/ConsoleTests/ConsoleTests.csproj index 1602b94..6d5d4f0 100644 --- a/Sources/Tests/ConsoleTests/ConsoleTests.csproj +++ b/Sources/Tests/ConsoleTests/ConsoleTests.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/Sources/Tests/LaConsolePourLaBdd/LaConsolePourLaBdd.csproj b/Sources/Tests/LaConsolePourLaBdd/LaConsolePourLaBdd.csproj deleted file mode 100644 index 725fe1d..0000000 --- a/Sources/Tests/LaConsolePourLaBdd/LaConsolePourLaBdd.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - Exe - net6.0 - enable - enable - - - - - - - - - - - - - - diff --git a/Sources/Tests/LaConsolePourLaBdd/Program.cs b/Sources/Tests/LaConsolePourLaBdd/Program.cs deleted file mode 100644 index e94ed74..0000000 --- a/Sources/Tests/LaConsolePourLaBdd/Program.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Model2; - -static void Main(string[] args) -{ - Nounours chewie = new Nounours { Nom = "Chewbacca", Naissance = new DateTime(1977, 5, 27), NbPoils = 1234567 }; - ChampionEntity c1 = new ChampionEntity(); - - //JAI PAS ENCORE FAIT - - - using (var context = new NounoursContext()) - { - // Crée des nounours et les insère dans la base - Console.WriteLine("Creates and inserts new Nounours"); - context.Add(chewie); - context.Add(yoda); - context.Add(ewok); - context.Add(c3po); - context.SaveChanges(); - } -} \ No newline at end of file diff --git a/Sources/TrucAuMilieu/Data.cs b/Sources/TrucAuMilieu/Data.cs new file mode 100644 index 0000000..96782b5 --- /dev/null +++ b/Sources/TrucAuMilieu/Data.cs @@ -0,0 +1,18 @@ +using LibEntityFramework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TrucAuMilieu +{ + public class Data + { + ChampionContext context = new ChampionContext(); + List listChampions() + { + return context.Champs.ToList(); + } + } +} diff --git a/Sources/TrucAuMilieu/TrucAuMilieu.csproj b/Sources/TrucAuMilieu/TrucAuMilieu.csproj new file mode 100644 index 0000000..446c0c5 --- /dev/null +++ b/Sources/TrucAuMilieu/TrucAuMilieu.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/Sources/TrucAuMilieu/toEntity.cs b/Sources/TrucAuMilieu/toEntity.cs new file mode 100644 index 0000000..b447545 --- /dev/null +++ b/Sources/TrucAuMilieu/toEntity.cs @@ -0,0 +1,13 @@ +using LibEntityFramework; +using Model; + +namespace TrucAuMilieu +{ + static class toEntity + { + public static ChampionEntity ToEntity(this Champion c) + { + return new ChampionEntity(c.Name, c.Bio, c.Icon); + } + } +} \ No newline at end of file