From 159f96a028b4e6b50b00cb6713b9fe0fa0560622 Mon Sep 17 00:00:00 2001 From: Maxence Lanone Date: Sun, 12 Feb 2023 16:38:14 +0100 Subject: [PATCH] :sparkles: ajout table player + creation bdd sqLite --- Sources/HelloWorldApp/HelloWorldApp.csproj | 8 --- Sources/HelloWorldApp/Program.cs | 12 ---- Sources/HelloWorldLib/Class1.cs | 11 ---- Sources/HelloWorldLib/HelloWorldLib.csproj | 10 ---- Sources/Tests/DbConsole/DbConsole.csproj | 27 +++++++++ .../20230212153116_MyMigration.Designer.cs | 53 +++++++++++++++++ .../Migrations/20230212153116_MyMigration.cs | 39 +++++++++++++ .../Migrations/SQLiteContextModelSnapshot.cs | 50 ++++++++++++++++ Sources/Tests/DbConsole/Program.cs | 30 ++++++++++ Sources/Tests/DbConsole/projet.Champions.db | Bin 0 -> 20480 bytes .../Tests/DbConsole/projet.Champions.db-shm | Bin 0 -> 32768 bytes .../Tests/DbConsole/projet.Champions.db-wal | 0 .../HelloWordLib_UnitTests.csproj | 4 +- Sources/Trek12_API.sln | 26 ++++----- Sources/Trek12_API/Trek12_API.csproj | 2 +- Sources/Trek12_Lib/EntityFrameWorkLib.csproj | 13 +++++ .../20230212152210_MyMigration.Designer.cs | 54 ++++++++++++++++++ .../Migrations/20230212152210_MyMigration.cs | 39 +++++++++++++ .../Migrations/TrekContextModelSnapshot.cs | 51 +++++++++++++++++ Sources/Trek12_Lib/PlayerEntity.cs | 18 +++++- Sources/Trek12_Lib/TrekContext.cs | 38 ++++++++++++ Sources/Trek12_Lib/projet.Players.db | Bin 0 -> 20480 bytes 22 files changed, 425 insertions(+), 60 deletions(-) delete mode 100644 Sources/HelloWorldApp/HelloWorldApp.csproj delete mode 100644 Sources/HelloWorldApp/Program.cs delete mode 100644 Sources/HelloWorldLib/Class1.cs delete mode 100644 Sources/HelloWorldLib/HelloWorldLib.csproj create mode 100644 Sources/Tests/DbConsole/DbConsole.csproj create mode 100644 Sources/Tests/DbConsole/Migrations/20230212153116_MyMigration.Designer.cs create mode 100644 Sources/Tests/DbConsole/Migrations/20230212153116_MyMigration.cs create mode 100644 Sources/Tests/DbConsole/Migrations/SQLiteContextModelSnapshot.cs create mode 100644 Sources/Tests/DbConsole/Program.cs create mode 100644 Sources/Tests/DbConsole/projet.Champions.db create mode 100644 Sources/Tests/DbConsole/projet.Champions.db-shm create mode 100644 Sources/Tests/DbConsole/projet.Champions.db-wal create mode 100644 Sources/Trek12_Lib/Migrations/20230212152210_MyMigration.Designer.cs create mode 100644 Sources/Trek12_Lib/Migrations/20230212152210_MyMigration.cs create mode 100644 Sources/Trek12_Lib/Migrations/TrekContextModelSnapshot.cs create mode 100644 Sources/Trek12_Lib/TrekContext.cs create mode 100644 Sources/Trek12_Lib/projet.Players.db diff --git a/Sources/HelloWorldApp/HelloWorldApp.csproj b/Sources/HelloWorldApp/HelloWorldApp.csproj deleted file mode 100644 index ddb344e..0000000 --- a/Sources/HelloWorldApp/HelloWorldApp.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - Exe - net6.0 - - - diff --git a/Sources/HelloWorldApp/Program.cs b/Sources/HelloWorldApp/Program.cs deleted file mode 100644 index 7db4615..0000000 --- a/Sources/HelloWorldApp/Program.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace HelloWorldApp -{ - class Program - { - static void Main(string[] args) - { - Console.WriteLine("Hello World!"); - } - } -} diff --git a/Sources/HelloWorldLib/Class1.cs b/Sources/HelloWorldLib/Class1.cs deleted file mode 100644 index 31eb072..0000000 --- a/Sources/HelloWorldLib/Class1.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace HelloWorldLib -{ - /// - ///a sample class - /// - public class Class1 - { - } -} diff --git a/Sources/HelloWorldLib/HelloWorldLib.csproj b/Sources/HelloWorldLib/HelloWorldLib.csproj deleted file mode 100644 index b1e238b..0000000 --- a/Sources/HelloWorldLib/HelloWorldLib.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - - net6.0 - - - - 4 - - diff --git a/Sources/Tests/DbConsole/DbConsole.csproj b/Sources/Tests/DbConsole/DbConsole.csproj new file mode 100644 index 0000000..92c43c9 --- /dev/null +++ b/Sources/Tests/DbConsole/DbConsole.csproj @@ -0,0 +1,27 @@ + + + + Exe + net6.0 + enable + enable + $(MSBuildProjectDirectory) + + + + + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/Sources/Tests/DbConsole/Migrations/20230212153116_MyMigration.Designer.cs b/Sources/Tests/DbConsole/Migrations/20230212153116_MyMigration.Designer.cs new file mode 100644 index 0000000..629e956 --- /dev/null +++ b/Sources/Tests/DbConsole/Migrations/20230212153116_MyMigration.Designer.cs @@ -0,0 +1,53 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DbConsole.Migrations +{ + [DbContext(typeof(SQLiteContext))] + [Migration("20230212153116_MyMigration")] + partial class MyMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b => + { + b.Property("PlayerId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("MaxPoints") + .HasColumnType("INTEGER"); + + b.Property("MaxZone") + .HasColumnType("INTEGER"); + + b.Property("NbPlayed") + .HasColumnType("INTEGER"); + + b.Property("NbPoints") + .HasColumnType("INTEGER"); + + b.Property("NbWin") + .HasColumnType("INTEGER"); + + b.Property("Pseudo") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("PlayerId"); + + b.ToTable("Players"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/Tests/DbConsole/Migrations/20230212153116_MyMigration.cs b/Sources/Tests/DbConsole/Migrations/20230212153116_MyMigration.cs new file mode 100644 index 0000000..98d2699 --- /dev/null +++ b/Sources/Tests/DbConsole/Migrations/20230212153116_MyMigration.cs @@ -0,0 +1,39 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DbConsole.Migrations +{ + /// + public partial class MyMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Players", + columns: table => new + { + PlayerId = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Pseudo = table.Column(type: "TEXT", nullable: false), + NbWin = table.Column(type: "INTEGER", nullable: false), + NbPlayed = table.Column(type: "INTEGER", nullable: false), + MaxZone = table.Column(type: "INTEGER", nullable: false), + MaxPoints = table.Column(type: "INTEGER", nullable: false), + NbPoints = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Players", x => x.PlayerId); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Players"); + } + } +} diff --git a/Sources/Tests/DbConsole/Migrations/SQLiteContextModelSnapshot.cs b/Sources/Tests/DbConsole/Migrations/SQLiteContextModelSnapshot.cs new file mode 100644 index 0000000..b5a68bd --- /dev/null +++ b/Sources/Tests/DbConsole/Migrations/SQLiteContextModelSnapshot.cs @@ -0,0 +1,50 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DbConsole.Migrations +{ + [DbContext(typeof(SQLiteContext))] + partial class SQLiteContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b => + { + b.Property("PlayerId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("MaxPoints") + .HasColumnType("INTEGER"); + + b.Property("MaxZone") + .HasColumnType("INTEGER"); + + b.Property("NbPlayed") + .HasColumnType("INTEGER"); + + b.Property("NbPoints") + .HasColumnType("INTEGER"); + + b.Property("NbWin") + .HasColumnType("INTEGER"); + + b.Property("Pseudo") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("PlayerId"); + + b.ToTable("Players"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/Tests/DbConsole/Program.cs b/Sources/Tests/DbConsole/Program.cs new file mode 100644 index 0000000..39b4675 --- /dev/null +++ b/Sources/Tests/DbConsole/Program.cs @@ -0,0 +1,30 @@ +using EntityFrameWorkLib; +using Microsoft.EntityFrameworkCore; + +PlayerEntity p1 = new PlayerEntity +{ + Pseudo = "Jax", + NbWin = 0, + NbPlayed = 0, + MaxZone = 0, + MaxPoints = 0, + NbPoints = 0 +}; + +using (var context = new SQLiteContext()) +{ + Console.WriteLine("Create and Insert new Champion"); + context.Add(p1); + context.SaveChanges(); +} + +public class SQLiteContext : TrekContext +{ + protected override void OnConfiguring(DbContextOptionsBuilder options) + { + if (!options.IsConfigured) + { + options.UseSqlite($"Data Source=projet.Champions.db"); + } + } +} diff --git a/Sources/Tests/DbConsole/projet.Champions.db b/Sources/Tests/DbConsole/projet.Champions.db new file mode 100644 index 0000000000000000000000000000000000000000..a73a11609e47e95a9de8f849854e57525c789d3f GIT binary patch literal 20480 zcmeI)&5qJg6bJBoTV{sAU`!byBqsEyxrV6VsHTnkGz}X-fi2 zCvJTdAIF_5Utwn9(gRb-@X-e#`QNnZ{Wv}M_6J?GB%Hr*d9f?L2H~X>iw1kdB#FHg zf-xr1zDN6_%-WengO2=OJ*_ISiv1+7{9~E?3-<80@+<$7DkucrZ6rKhUR6OI^#FE9=sJ;Y*V<&mX#z%A5wzXTPTP-`g-SV_^0Xa0oyE0uX=z1Rwwb2tWV=5P$##HU%E=EPI@tm3PkM?)m?g nDYu(}=z#zPAOHafKmY;|fB*y_009U - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/Sources/Trek12_API.sln b/Sources/Trek12_API.sln index 995c99d..101180a 100644 --- a/Sources/Trek12_API.sln +++ b/Sources/Trek12_API.sln @@ -5,36 +5,36 @@ VisualStudioVersion = 16.0.810.22 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{C75DF644-C41F-4A08-8B69-C8554204AC72}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWordLib_UnitTests", "Tests\HelloWordLib_UnitTests\HelloWordLib_UnitTests.csproj", "{F9B12DFD-EF58-429F-9344-70DFC10EC6E5}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Trek12_API", "Trek12_API\Trek12_API.csproj", "{3BF053E1-44DF-4305-ACBA-21F7A053A514}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameWorkLib", "Trek12_Lib\EntityFrameWorkLib.csproj", "{E22E6061-91C0-4503-AFC8-8D01912D3AA0}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{4BEFD382-A3A4-444E-973E-73F410F9CED4}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameWorkLib", "Trek12_Lib\EntityFrameWorkLib.csproj", "{D6B8B866-0510-454A-A00A-BF403E81CE3E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbConsole", "Tests\DbConsole\DbConsole.csproj", "{75B303CC-F36E-46FA-BE23-05EEA35D9B28}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {F9B12DFD-EF58-429F-9344-70DFC10EC6E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F9B12DFD-EF58-429F-9344-70DFC10EC6E5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F9B12DFD-EF58-429F-9344-70DFC10EC6E5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F9B12DFD-EF58-429F-9344-70DFC10EC6E5}.Release|Any CPU.Build.0 = Release|Any CPU {3BF053E1-44DF-4305-ACBA-21F7A053A514}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3BF053E1-44DF-4305-ACBA-21F7A053A514}.Debug|Any CPU.Build.0 = Debug|Any CPU {3BF053E1-44DF-4305-ACBA-21F7A053A514}.Release|Any CPU.ActiveCfg = Release|Any CPU {3BF053E1-44DF-4305-ACBA-21F7A053A514}.Release|Any CPU.Build.0 = Release|Any CPU - {E22E6061-91C0-4503-AFC8-8D01912D3AA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E22E6061-91C0-4503-AFC8-8D01912D3AA0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E22E6061-91C0-4503-AFC8-8D01912D3AA0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E22E6061-91C0-4503-AFC8-8D01912D3AA0}.Release|Any CPU.Build.0 = Release|Any CPU {4BEFD382-A3A4-444E-973E-73F410F9CED4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4BEFD382-A3A4-444E-973E-73F410F9CED4}.Debug|Any CPU.Build.0 = Debug|Any CPU {4BEFD382-A3A4-444E-973E-73F410F9CED4}.Release|Any CPU.ActiveCfg = Release|Any CPU {4BEFD382-A3A4-444E-973E-73F410F9CED4}.Release|Any CPU.Build.0 = Release|Any CPU + {D6B8B866-0510-454A-A00A-BF403E81CE3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D6B8B866-0510-454A-A00A-BF403E81CE3E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D6B8B866-0510-454A-A00A-BF403E81CE3E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D6B8B866-0510-454A-A00A-BF403E81CE3E}.Release|Any CPU.Build.0 = Release|Any CPU + {75B303CC-F36E-46FA-BE23-05EEA35D9B28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {75B303CC-F36E-46FA-BE23-05EEA35D9B28}.Debug|Any CPU.Build.0 = Debug|Any CPU + {75B303CC-F36E-46FA-BE23-05EEA35D9B28}.Release|Any CPU.ActiveCfg = Release|Any CPU + {75B303CC-F36E-46FA-BE23-05EEA35D9B28}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -43,6 +43,6 @@ Global SolutionGuid = {4D47853B-D1A3-49A5-84BA-CD2DC65FD105} EndGlobalSection GlobalSection(NestedProjects) = preSolution - {F9B12DFD-EF58-429F-9344-70DFC10EC6E5} = {C75DF644-C41F-4A08-8B69-C8554204AC72} + {75B303CC-F36E-46FA-BE23-05EEA35D9B28} = {C75DF644-C41F-4A08-8B69-C8554204AC72} EndGlobalSection EndGlobal diff --git a/Sources/Trek12_API/Trek12_API.csproj b/Sources/Trek12_API/Trek12_API.csproj index 4289e82..8cb33cf 100644 --- a/Sources/Trek12_API/Trek12_API.csproj +++ b/Sources/Trek12_API/Trek12_API.csproj @@ -7,7 +7,7 @@ - + diff --git a/Sources/Trek12_Lib/EntityFrameWorkLib.csproj b/Sources/Trek12_Lib/EntityFrameWorkLib.csproj index 559bdcc..b8e4722 100644 --- a/Sources/Trek12_Lib/EntityFrameWorkLib.csproj +++ b/Sources/Trek12_Lib/EntityFrameWorkLib.csproj @@ -7,4 +7,17 @@ Trek12_Lib + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + diff --git a/Sources/Trek12_Lib/Migrations/20230212152210_MyMigration.Designer.cs b/Sources/Trek12_Lib/Migrations/20230212152210_MyMigration.Designer.cs new file mode 100644 index 0000000..1eae5ae --- /dev/null +++ b/Sources/Trek12_Lib/Migrations/20230212152210_MyMigration.Designer.cs @@ -0,0 +1,54 @@ +// +using EntityFrameWorkLib; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EntityFrameWorkLib.Migrations +{ + [DbContext(typeof(TrekContext))] + [Migration("20230212152210_MyMigration")] + partial class MyMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b => + { + b.Property("PlayerId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("MaxPoints") + .HasColumnType("INTEGER"); + + b.Property("MaxZone") + .HasColumnType("INTEGER"); + + b.Property("NbPlayed") + .HasColumnType("INTEGER"); + + b.Property("NbPoints") + .HasColumnType("INTEGER"); + + b.Property("NbWin") + .HasColumnType("INTEGER"); + + b.Property("Pseudo") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("PlayerId"); + + b.ToTable("Players"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/Trek12_Lib/Migrations/20230212152210_MyMigration.cs b/Sources/Trek12_Lib/Migrations/20230212152210_MyMigration.cs new file mode 100644 index 0000000..704ad5f --- /dev/null +++ b/Sources/Trek12_Lib/Migrations/20230212152210_MyMigration.cs @@ -0,0 +1,39 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EntityFrameWorkLib.Migrations +{ + /// + public partial class MyMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Players", + columns: table => new + { + PlayerId = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Pseudo = table.Column(type: "TEXT", nullable: false), + NbWin = table.Column(type: "INTEGER", nullable: false), + NbPlayed = table.Column(type: "INTEGER", nullable: false), + MaxZone = table.Column(type: "INTEGER", nullable: false), + MaxPoints = table.Column(type: "INTEGER", nullable: false), + NbPoints = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Players", x => x.PlayerId); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Players"); + } + } +} diff --git a/Sources/Trek12_Lib/Migrations/TrekContextModelSnapshot.cs b/Sources/Trek12_Lib/Migrations/TrekContextModelSnapshot.cs new file mode 100644 index 0000000..a66ff04 --- /dev/null +++ b/Sources/Trek12_Lib/Migrations/TrekContextModelSnapshot.cs @@ -0,0 +1,51 @@ +// +using EntityFrameWorkLib; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EntityFrameWorkLib.Migrations +{ + [DbContext(typeof(TrekContext))] + partial class TrekContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b => + { + b.Property("PlayerId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("MaxPoints") + .HasColumnType("INTEGER"); + + b.Property("MaxZone") + .HasColumnType("INTEGER"); + + b.Property("NbPlayed") + .HasColumnType("INTEGER"); + + b.Property("NbPoints") + .HasColumnType("INTEGER"); + + b.Property("NbWin") + .HasColumnType("INTEGER"); + + b.Property("Pseudo") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("PlayerId"); + + b.ToTable("Players"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/Trek12_Lib/PlayerEntity.cs b/Sources/Trek12_Lib/PlayerEntity.cs index 4941d9b..174b399 100644 --- a/Sources/Trek12_Lib/PlayerEntity.cs +++ b/Sources/Trek12_Lib/PlayerEntity.cs @@ -1,6 +1,18 @@ -namespace Trek12_Lib; -public class Class1 -{ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +namespace EntityFrameWorkLib; +public class PlayerEntity +{ + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int PlayerId {get; set;} + public string Pseudo { get; set; } + public int NbWin { get; set; } + public int NbPlayed { get; set; } + public int MaxZone { get; set; } + public int MaxPoints { get; set; } + public int NbPoints { get; set; } } diff --git a/Sources/Trek12_Lib/TrekContext.cs b/Sources/Trek12_Lib/TrekContext.cs new file mode 100644 index 0000000..d1d3a57 --- /dev/null +++ b/Sources/Trek12_Lib/TrekContext.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Data.Common; +using System.Reflection.Emit; +using Microsoft.EntityFrameworkCore; + +namespace EntityFrameWorkLib +{ + public class TrekContext : DbContext + { + public DbSet Players { get; set; } + + public TrekContext() { } + public TrekContext(DbContextOptions options) + : base(options) + { } + protected override void OnConfiguring(DbContextOptionsBuilder options) + { + if (!options.IsConfigured) + { + base.OnConfiguring(options.UseSqlite($"DataSource=projet.Players.db")); + } + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + //Définition de la clé primaire de PlayerEntity + modelBuilder.Entity().HasKey(n => n.PlayerId); + //Définition du mode de generation de la clé : génération à l'insertion + modelBuilder.Entity().Property(n => n.PlayerId).ValueGeneratedOnAdd(); + + base.OnModelCreating(modelBuilder); + + } + + } +} + diff --git a/Sources/Trek12_Lib/projet.Players.db b/Sources/Trek12_Lib/projet.Players.db new file mode 100644 index 0000000000000000000000000000000000000000..3928b180e9d021f618723faed8f4809510c34a9e GIT binary patch literal 20480 zcmeI&-)fss90%~DN!vA$Wp~2L;NVq5OGqpu7rU7&XR9=t%$jW(3^9!zLaI~^G?y#8 z-J|qzcDJiO#V+?tFw$iD04d*t;`#IQcl4uPXmatf7okh4}vS?RV4cbbN>Sa}#wcMBW#$Q&gzhTdRH}31dsDc6k2tWV=5P$##AOHafKw!HB z2Gw2V=tvr+-gxRKH&c3#aufe%=7*P?&7D(Q=#Joy{;ntZM(kneUHiwhXY)=}_LPGI z>8H2MIhcBLKTfhubuEXQ^{V`^#;Ig&W1@1ya>NH=bF1%gYuM}Y)4p}#*gEx7*twhU zIj{{=w@3V3jJQ5@`i4bQn8I?7vy_QHn?x#i#23nxWy{8_@#i4?f3AFVIZ466WC5mk z`!x#v(gZXn4ASk8pZR%PI=w9 zFeVqzQ!dcgj5ftf@;vfiiO11ocA0*nt4@cyk+s$|jOG7Z;}n0SG_<0uX=z1Rwwb2tWV= I5Xc1n0jN6mL;wH) literal 0 HcmV?d00001