From 568df4befd0e4ac3b252cc61e44c88cba7d19aed Mon Sep 17 00:00:00 2001 From: jboinembalome Date: Fri, 30 Oct 2020 17:20:16 +0100 Subject: [PATCH] Ajout de l'optionBuilder pour l'epContext + utilisation de la classe DataSeeder --- EPAServeur/EPAServeur.csproj | 1 + EPAServeur/Startup.cs | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/EPAServeur/EPAServeur.csproj b/EPAServeur/EPAServeur.csproj index b88d2f0..6f38212 100644 --- a/EPAServeur/EPAServeur.csproj +++ b/EPAServeur/EPAServeur.csproj @@ -8,6 +8,7 @@ + diff --git a/EPAServeur/Startup.cs b/EPAServeur/Startup.cs index 2efbb17..e46b8f2 100644 --- a/EPAServeur/Startup.cs +++ b/EPAServeur/Startup.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -83,15 +84,23 @@ namespace EPAServeur }; }); - services.AddDbContext(); - using (var context = new EpContext()) + services.AddDbContext(b => b.UseMySQL(Configuration["Data:DefaultConnection:ConnectionString"])); + + var optionBuider = new DbContextOptionsBuilder() + .UseMySQL(Configuration["Data:DefaultConnection:ConnectionString"]) + .Options; + + using (var context = new EpContext(optionBuider)) { context.Database.EnsureDeleted(); //PENSEZ A ENLEVER CETTE LIGNE ET A NE JAMAIS LA REMETTRE QUAND LE SERVEUR SERA MIS EN PRODUCTION ^^ context.Database.EnsureCreated(); context.SaveChanges(); - context.AjoutInformationsDeBase(); - context.AjoutChamps(); - context.AjouterNotes(); + + DataSeeder.AddInformationsDeBase(context); + DataSeeder.AddChamps(context); + DataSeeder.AddNotes(context); + DataSeeder.AddEp(context); + DataSeeder.AddEngagements(context); } //faire using, check si kekchoz exkist puis appeler les m�thodes de cr�ation si il n'y a rien