diff --git a/.vs/League-of-Legends_Project3/v17/.wsuo b/.vs/League-of-Legends_Project3/v17/.wsuo new file mode 100644 index 0000000..5e22404 Binary files /dev/null and b/.vs/League-of-Legends_Project3/v17/.wsuo differ diff --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 0000000..2643996 Binary files /dev/null and b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db differ diff --git a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-shm b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-shm new file mode 100644 index 0000000..18b64da Binary files /dev/null and b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-shm differ diff --git a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-wal b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-wal new file mode 100644 index 0000000..c1c99f1 Binary files /dev/null and b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-wal differ diff --git a/EntityFramework_LoL/Sources/Entities/Entities.csproj b/EntityFramework_LoL/Sources/Entities/Entities.csproj new file mode 100644 index 0000000..3707fee --- /dev/null +++ b/EntityFramework_LoL/Sources/Entities/Entities.csproj @@ -0,0 +1,24 @@ + + + + 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) + + + + + + +