diff --git a/Sources/EFLol/ChampionContext.cs b/Sources/EFLol/ChampionContext.cs index d1333c0..c4eaf71 100644 --- a/Sources/EFLol/ChampionContext.cs +++ b/Sources/EFLol/ChampionContext.cs @@ -1,19 +1,30 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; - -namespace EFLol -{ - internal class ChampionContext : DbContext - { - public DbSet Champions { get; set; } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseSqlite("Data Source=loldb.db"); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; + +namespace EFLol +{ + internal class ChampionContext : DbContext + { + public DbSet Champions { get; set; } + + public ChampionContext() + { } + + public ChampionContext(DbContextOptions options) + : base(options) + { } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (!optionsBuilder.IsConfigured) + { + //optionsBuilder.UseSqlServer("Data Source=loldb.db"); + optionsBuilder.UseSqlite("Data Source=loldb.db"); + } + } + } +} diff --git a/Sources/EFLol/EFLol.csproj b/Sources/EFLol/EFLol.csproj index c55d3a4..740e3bf 100644 --- a/Sources/EFLol/EFLol.csproj +++ b/Sources/EFLol/EFLol.csproj @@ -16,6 +16,11 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Sources/EFLol/Migrations/20230201162158_FirstMig.Designer.cs b/Sources/EFLol/Migrations/20230204100025_migration1.Designer.cs similarity index 91% rename from Sources/EFLol/Migrations/20230201162158_FirstMig.Designer.cs rename to Sources/EFLol/Migrations/20230204100025_migration1.Designer.cs index 29614aa..9f54093 100644 --- a/Sources/EFLol/Migrations/20230201162158_FirstMig.Designer.cs +++ b/Sources/EFLol/Migrations/20230204100025_migration1.Designer.cs @@ -1,43 +1,43 @@ -// -using EFLol; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EFLol.Migrations -{ - [DbContext(typeof(ChampionContext))] - [Migration("20230201162158_FirstMig")] - partial class FirstMig - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("EFLol.ChampionEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Bio") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Name") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Champions"); - }); -#pragma warning restore 612, 618 - } - } -} +// +using EFLol; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EFLol.Migrations +{ + [DbContext(typeof(ChampionContext))] + [Migration("20230204100025_migration1")] + partial class migration1 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("EFLol.ChampionEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Bio") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Champions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EFLol/Migrations/20230201162158_FirstMig.cs b/Sources/EFLol/Migrations/20230204100025_migration1.cs similarity index 92% rename from Sources/EFLol/Migrations/20230201162158_FirstMig.cs rename to Sources/EFLol/Migrations/20230204100025_migration1.cs index 59c3ac5..34b673a 100644 --- a/Sources/EFLol/Migrations/20230201162158_FirstMig.cs +++ b/Sources/EFLol/Migrations/20230204100025_migration1.cs @@ -1,35 +1,35 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace EFLol.Migrations -{ - /// - public partial class FirstMig : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Champions", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Name = table.Column(type: "TEXT", nullable: false), - Bio = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Champions", x => x.Id); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Champions"); - } - } -} +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EFLol.Migrations +{ + /// + public partial class migration1 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Champions", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: false), + Bio = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Champions", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Champions"); + } + } +} diff --git a/Sources/EFLol/Migrations/ChampionContextModelSnapshot.cs b/Sources/EFLol/Migrations/ChampionContextModelSnapshot.cs index cf6018a..d843a6a 100644 --- a/Sources/EFLol/Migrations/ChampionContextModelSnapshot.cs +++ b/Sources/EFLol/Migrations/ChampionContextModelSnapshot.cs @@ -1,40 +1,40 @@ -// -using EFLol; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EFLol.Migrations -{ - [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("EFLol.ChampionEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Bio") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Name") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Champions"); - }); -#pragma warning restore 612, 618 - } - } -} +// +using EFLol; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EFLol.Migrations +{ + [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("EFLol.ChampionEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Bio") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Champions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EFLol/Program.cs b/Sources/EFLol/Program.cs index 775f405..2422dc4 100644 --- a/Sources/EFLol/Program.cs +++ b/Sources/EFLol/Program.cs @@ -1,6 +1,6 @@ using EFLol; -ChampionEntity Zeus = new ChampionEntity +/*ChampionEntity Zeus = new ChampionEntity { Name = "Zeus", Bio = "Zeus is the king of the gods." @@ -11,4 +11,27 @@ using (var context = new ChampionContext()) Console.WriteLine("Adding Zeus to the database..."); context.Champions.Add(Zeus); context.SaveChanges(); +}*/ + +ChampionEntity chewie = new ChampionEntity { Name = "Chewbacca", Bio = "Zeus is the king of the gods." }; +ChampionEntity yoda = new ChampionEntity { Name = "Yoda", Bio = "Zeus is the king of the gods." }; +ChampionEntity ewok = new ChampionEntity { Name = "Ewok" , Bio = "Zeus is the king of the gods." }; + +using (var context = new ChampionContext()) +{ + // 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.SaveChanges(); +} + +using (var context = new ChampionContext()) +{ + foreach (var n in context.Champions) + { + Console.WriteLine($"{n.Id} - {n.Name}"); + } + context.SaveChanges(); } \ No newline at end of file diff --git a/Sources/EFLol/loldb.db b/Sources/EFLol/loldb.db index ef35bd0..528f860 100644 Binary files a/Sources/EFLol/loldb.db and b/Sources/EFLol/loldb.db differ diff --git a/Sources/Model/Model.csproj b/Sources/Model/Model.csproj index 89f6363..63fa530 100644 --- a/Sources/Model/Model.csproj +++ b/Sources/Model/Model.csproj @@ -12,6 +12,14 @@ + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/Sources/Model/loldb.db b/Sources/Model/loldb.db new file mode 100644 index 0000000..c5e7c15 Binary files /dev/null and b/Sources/Model/loldb.db differ diff --git a/Sources/Shared/Shared.csproj b/Sources/Shared/Shared.csproj index 132c02c..000356c 100644 --- a/Sources/Shared/Shared.csproj +++ b/Sources/Shared/Shared.csproj @@ -6,4 +6,13 @@ enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/Sources/StubLib/StubLib.csproj b/Sources/StubLib/StubLib.csproj index 1b714b9..a51603e 100644 --- a/Sources/StubLib/StubLib.csproj +++ b/Sources/StubLib/StubLib.csproj @@ -6,6 +6,15 @@ enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/Sources/TestUnitaireAPiLol/TestUnitaireAPiLol.csproj b/Sources/TestUnitaireAPiLol/TestUnitaireAPiLol.csproj index ed41633..393919a 100644 --- a/Sources/TestUnitaireAPiLol/TestUnitaireAPiLol.csproj +++ b/Sources/TestUnitaireAPiLol/TestUnitaireAPiLol.csproj @@ -9,6 +9,12 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Sources/Tests/ConsoleTests/ConsoleTests.csproj b/Sources/Tests/ConsoleTests/ConsoleTests.csproj index c52655b..69373bc 100644 --- a/Sources/Tests/ConsoleTests/ConsoleTests.csproj +++ b/Sources/Tests/ConsoleTests/ConsoleTests.csproj @@ -15,6 +15,12 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Sources/apiLOL/apiLOL.csproj b/Sources/apiLOL/apiLOL.csproj index 33350f8..f112330 100644 --- a/Sources/apiLOL/apiLOL.csproj +++ b/Sources/apiLOL/apiLOL.csproj @@ -7,6 +7,12 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive +