From 5e9583329c5e60aab66b3d4a96d1736bc92a8a21 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Wed, 1 Feb 2023 17:32:11 +0100 Subject: [PATCH] Creation BD + ajout lligne dedans --- Sources/EFLol/ChampionContext.cs | 4 +- .../EFLol/{Champion.cs => ChampionEntity.cs} | 3 +- Sources/EFLol/EFLol.csproj | 4 +- .../20230201162158_FirstMig.Designer.cs | 43 ++++++++++++++++++ .../Migrations/20230201162158_FirstMig.cs | 35 ++++++++++++++ .../ChampionContextModelSnapshot.cs | 40 ++++++++++++++++ Sources/EFLol/Program.cs | 16 ++++++- Sources/EFLol/loldb.db | Bin 0 -> 20480 bytes 8 files changed, 139 insertions(+), 6 deletions(-) rename Sources/EFLol/{Champion.cs => ChampionEntity.cs} (77%) create mode 100644 Sources/EFLol/Migrations/20230201162158_FirstMig.Designer.cs create mode 100644 Sources/EFLol/Migrations/20230201162158_FirstMig.cs create mode 100644 Sources/EFLol/Migrations/ChampionContextModelSnapshot.cs create mode 100644 Sources/EFLol/loldb.db diff --git a/Sources/EFLol/ChampionContext.cs b/Sources/EFLol/ChampionContext.cs index fd63455..d1333c0 100644 --- a/Sources/EFLol/ChampionContext.cs +++ b/Sources/EFLol/ChampionContext.cs @@ -9,11 +9,11 @@ namespace EFLol { internal class ChampionContext : DbContext { - public DbSet Champions { get; set; } + public DbSet Champions { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlite("Data Source=Champions.db"); + optionsBuilder.UseSqlite("Data Source=loldb.db"); } } } diff --git a/Sources/EFLol/Champion.cs b/Sources/EFLol/ChampionEntity.cs similarity index 77% rename from Sources/EFLol/Champion.cs rename to Sources/EFLol/ChampionEntity.cs index c067647..e9fe819 100644 --- a/Sources/EFLol/Champion.cs +++ b/Sources/EFLol/ChampionEntity.cs @@ -6,8 +6,9 @@ using System.Threading.Tasks; namespace EFLol { - internal class Champion + internal class ChampionEntity { + public int Id { get; set; } public string Name { get; set; } public string Bio { get; set; } } diff --git a/Sources/EFLol/EFLol.csproj b/Sources/EFLol/EFLol.csproj index 4d8e532..c55d3a4 100644 --- a/Sources/EFLol/EFLol.csproj +++ b/Sources/EFLol/EFLol.csproj @@ -1,10 +1,11 @@ - + Exe net6.0 enable enable + $(MSBuildProjectDirectory) @@ -17,4 +18,5 @@ + diff --git a/Sources/EFLol/Migrations/20230201162158_FirstMig.Designer.cs b/Sources/EFLol/Migrations/20230201162158_FirstMig.Designer.cs new file mode 100644 index 0000000..29614aa --- /dev/null +++ b/Sources/EFLol/Migrations/20230201162158_FirstMig.Designer.cs @@ -0,0 +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 + } + } +} diff --git a/Sources/EFLol/Migrations/20230201162158_FirstMig.cs b/Sources/EFLol/Migrations/20230201162158_FirstMig.cs new file mode 100644 index 0000000..59c3ac5 --- /dev/null +++ b/Sources/EFLol/Migrations/20230201162158_FirstMig.cs @@ -0,0 +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"); + } + } +} diff --git a/Sources/EFLol/Migrations/ChampionContextModelSnapshot.cs b/Sources/EFLol/Migrations/ChampionContextModelSnapshot.cs new file mode 100644 index 0000000..cf6018a --- /dev/null +++ b/Sources/EFLol/Migrations/ChampionContextModelSnapshot.cs @@ -0,0 +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 + } + } +} diff --git a/Sources/EFLol/Program.cs b/Sources/EFLol/Program.cs index 3751555..775f405 100644 --- a/Sources/EFLol/Program.cs +++ b/Sources/EFLol/Program.cs @@ -1,2 +1,14 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using EFLol; + +ChampionEntity Zeus = new ChampionEntity +{ + Name = "Zeus", + Bio = "Zeus is the king of the gods." +}; + +using (var context = new ChampionContext()) +{ + Console.WriteLine("Adding Zeus to the database..."); + context.Champions.Add(Zeus); + context.SaveChanges(); +} \ No newline at end of file diff --git a/Sources/EFLol/loldb.db b/Sources/EFLol/loldb.db new file mode 100644 index 0000000000000000000000000000000000000000..ef35bd0418c784d5fbba46faa9a9afb18701dc67 GIT binary patch literal 20480 zcmeI)(NEey90%|_DKN=u_p&tcg-eqq8V!M(4HI8PQe7hyR_h{5mZnO@MrmhTlI_v` zKl>B>C-&ykp7sy;w8tF?3>x|eFu#{xxVv6|z2B#OX(60^Xn3*9E`zY|#B7JWB9xMS z#t0#KUbDPTN{%;#Nr!*ZnRZ$;PfGT>DE%RVcu&OpwV%?DH7RW}#vuR!2tWV=5P$## zAOHafKp;h+E#%~_E!v5l^BXt1z2Q%CcI4g;T>m23&DKq=W@*f-9W*qSn7iRSeRrE5 zxp}vr&&$Ok{oWeItY10(FJ9nB(}pk?N12W*Y(p$CUKG8nFx{}UBh6$+%VNf9qrvJe z~y6bL{70uX=z1Rwwb2tWV=5P$##mRVpuv$vY^65#3k{|6#Hkl}9vR+c$U ztQ`UnfB*y_009U<00Izz00bcL>;&FWfxJHY