Ajout de l'optionBuilder pour l'epContext + utilisation de la classe DataSeeder

develop
jboinembalome 4 years ago
parent a07e54c6bc
commit 568df4befd
  1. 1
      EPAServeur/EPAServeur.csproj
  2. 19
      EPAServeur/Startup.cs

@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.7" />
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.21" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="RestSharp" Version="106.11.4" />

@ -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<EpContext>();
using (var context = new EpContext())
services.AddDbContext<EpContext>(b => b.UseMySQL(Configuration["Data:DefaultConnection:ConnectionString"]));
var optionBuider = new DbContextOptionsBuilder<EpContext>()
.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<EFBFBD>thodes de cr<EFBFBD>ation si il n'y a rien

Loading…
Cancel
Save