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 0000000..a73a116 Binary files /dev/null and b/Sources/Tests/DbConsole/projet.Champions.db differ diff --git a/Sources/Tests/DbConsole/projet.Champions.db-shm b/Sources/Tests/DbConsole/projet.Champions.db-shm new file mode 100644 index 0000000..fe9ac28 Binary files /dev/null and b/Sources/Tests/DbConsole/projet.Champions.db-shm differ diff --git a/Sources/Tests/DbConsole/projet.Champions.db-wal b/Sources/Tests/DbConsole/projet.Champions.db-wal new file mode 100644 index 0000000..e69de29 diff --git a/Sources/Tests/HelloWordLib_UnitTests/HelloWordLib_UnitTests.csproj b/Sources/Tests/HelloWordLib_UnitTests/HelloWordLib_UnitTests.csproj index 1fb4e4d..3449733 100644 --- a/Sources/Tests/HelloWordLib_UnitTests/HelloWordLib_UnitTests.csproj +++ b/Sources/Tests/HelloWordLib_UnitTests/HelloWordLib_UnitTests.csproj @@ -7,13 +7,13 @@ - + 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 0000000..3928b18 Binary files /dev/null and b/Sources/Trek12_Lib/projet.Players.db differ