ajout table player + creation bdd sqLite

EF
Maxence LANONE 2 years ago
parent b2273c5ccb
commit 159f96a028

@ -1,8 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
</Project>

@ -1,12 +0,0 @@
using System;
namespace HelloWorldApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

@ -1,11 +0,0 @@
using System;
namespace HelloWorldLib
{
///<summary>
///a sample class
///</summary>
public class Class1
{
}
}

@ -1,10 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<WarningLevel>4</WarningLevel>
</PropertyGroup>
</Project>

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartWorkingDirectory>$(MSBuildProjectDirectory)</StartWorkingDirectory>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Trek12_Lib\EntityFrameWorkLib.csproj" />
</ItemGroup>
<ItemGroup>
<None Remove="Microsoft.EntityFrameworkCore" />
<None Remove="Microsoft.EntityFrameworkCore.Tools" />
<None Remove="Microsoft.EntityFrameworkCore.Sqlite" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.2" />
</ItemGroup>
</Project>

@ -0,0 +1,53 @@
// <auto-generated />
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
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b =>
{
b.Property<int>("PlayerId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("MaxPoints")
.HasColumnType("INTEGER");
b.Property<int>("MaxZone")
.HasColumnType("INTEGER");
b.Property<int>("NbPlayed")
.HasColumnType("INTEGER");
b.Property<int>("NbPoints")
.HasColumnType("INTEGER");
b.Property<int>("NbWin")
.HasColumnType("INTEGER");
b.Property<string>("Pseudo")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("PlayerId");
b.ToTable("Players");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,39 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DbConsole.Migrations
{
/// <inheritdoc />
public partial class MyMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Players",
columns: table => new
{
PlayerId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Pseudo = table.Column<string>(type: "TEXT", nullable: false),
NbWin = table.Column<int>(type: "INTEGER", nullable: false),
NbPlayed = table.Column<int>(type: "INTEGER", nullable: false),
MaxZone = table.Column<int>(type: "INTEGER", nullable: false),
MaxPoints = table.Column<int>(type: "INTEGER", nullable: false),
NbPoints = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Players", x => x.PlayerId);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Players");
}
}
}

@ -0,0 +1,50 @@
// <auto-generated />
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<int>("PlayerId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("MaxPoints")
.HasColumnType("INTEGER");
b.Property<int>("MaxZone")
.HasColumnType("INTEGER");
b.Property<int>("NbPlayed")
.HasColumnType("INTEGER");
b.Property<int>("NbPoints")
.HasColumnType("INTEGER");
b.Property<int>("NbWin")
.HasColumnType("INTEGER");
b.Property<string>("Pseudo")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("PlayerId");
b.ToTable("Players");
});
#pragma warning restore 612, 618
}
}
}

@ -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");
}
}
}

@ -7,13 +7,13 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" /> <PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
</PackageReference> </PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2"> <PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
</PackageReference> </PackageReference>

@ -5,36 +5,36 @@ VisualStudioVersion = 16.0.810.22
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{C75DF644-C41F-4A08-8B69-C8554204AC72}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{C75DF644-C41F-4A08-8B69-C8554204AC72}"
EndProject 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}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Trek12_API", "Trek12_API\Trek12_API.csproj", "{3BF053E1-44DF-4305-ACBA-21F7A053A514}"
EndProject 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}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{4BEFD382-A3A4-444E-973E-73F410F9CED4}"
EndProject 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 Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution 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.ActiveCfg = Debug|Any CPU
{3BF053E1-44DF-4305-ACBA-21F7A053A514}.Debug|Any CPU.Build.0 = 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.ActiveCfg = Release|Any CPU
{3BF053E1-44DF-4305-ACBA-21F7A053A514}.Release|Any CPU.Build.0 = 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.ActiveCfg = Debug|Any CPU
{4BEFD382-A3A4-444E-973E-73F410F9CED4}.Debug|Any CPU.Build.0 = 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.ActiveCfg = Release|Any CPU
{4BEFD382-A3A4-444E-973E-73F410F9CED4}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -43,6 +43,6 @@ Global
SolutionGuid = {4D47853B-D1A3-49A5-84BA-CD2DC65FD105} SolutionGuid = {4D47853B-D1A3-49A5-84BA-CD2DC65FD105}
EndGlobalSection EndGlobalSection
GlobalSection(NestedProjects) = preSolution GlobalSection(NestedProjects) = preSolution
{F9B12DFD-EF58-429F-9344-70DFC10EC6E5} = {C75DF644-C41F-4A08-8B69-C8554204AC72} {75B303CC-F36E-46FA-BE23-05EEA35D9B28} = {C75DF644-C41F-4A08-8B69-C8554204AC72}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

@ -7,7 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -7,4 +7,17 @@
<AssemblyName>Trek12_Lib</AssemblyName> <AssemblyName>Trek12_Lib</AssemblyName>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<None Remove="Microsoft.EntityFrameworkCore" />
<None Remove="Microsoft.EntityFrameworkCore.Sqlite" />
<None Remove="Microsoft.EntityFrameworkCore.Tools" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project> </Project>

@ -0,0 +1,54 @@
// <auto-generated />
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
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b =>
{
b.Property<int>("PlayerId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("MaxPoints")
.HasColumnType("INTEGER");
b.Property<int>("MaxZone")
.HasColumnType("INTEGER");
b.Property<int>("NbPlayed")
.HasColumnType("INTEGER");
b.Property<int>("NbPoints")
.HasColumnType("INTEGER");
b.Property<int>("NbWin")
.HasColumnType("INTEGER");
b.Property<string>("Pseudo")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("PlayerId");
b.ToTable("Players");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,39 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFrameWorkLib.Migrations
{
/// <inheritdoc />
public partial class MyMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Players",
columns: table => new
{
PlayerId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Pseudo = table.Column<string>(type: "TEXT", nullable: false),
NbWin = table.Column<int>(type: "INTEGER", nullable: false),
NbPlayed = table.Column<int>(type: "INTEGER", nullable: false),
MaxZone = table.Column<int>(type: "INTEGER", nullable: false),
MaxPoints = table.Column<int>(type: "INTEGER", nullable: false),
NbPoints = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Players", x => x.PlayerId);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Players");
}
}
}

@ -0,0 +1,51 @@
// <auto-generated />
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<int>("PlayerId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("MaxPoints")
.HasColumnType("INTEGER");
b.Property<int>("MaxZone")
.HasColumnType("INTEGER");
b.Property<int>("NbPlayed")
.HasColumnType("INTEGER");
b.Property<int>("NbPoints")
.HasColumnType("INTEGER");
b.Property<int>("NbWin")
.HasColumnType("INTEGER");
b.Property<string>("Pseudo")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("PlayerId");
b.ToTable("Players");
});
#pragma warning restore 612, 618
}
}
}

@ -1,6 +1,18 @@
namespace Trek12_Lib; using System;
public class Class1 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; }
} }

@ -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<PlayerEntity> Players { get; set; }
public TrekContext() { }
public TrekContext(DbContextOptions<TrekContext> 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<PlayerEntity>().HasKey(n => n.PlayerId);
//Définition du mode de generation de la clé : génération à l'insertion
modelBuilder.Entity<PlayerEntity>().Property(n => n.PlayerId).ValueGeneratedOnAdd();
base.OnModelCreating(modelBuilder);
}
}
}
Loading…
Cancel
Save