unterstüzung für MySql;

This commit is contained in:
2020-06-12 20:00:14 +02:00
parent dc19188392
commit 50fe69662d
7 changed files with 281 additions and 575 deletions

View File

@@ -27,15 +27,28 @@ namespace MultipleChoiceTrainer
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
AddDbContext(services);
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddControllersWithViews();
services.AddRazorPages();
}
private void AddDbContext(IServiceCollection services)
{
var connectionString = Configuration.GetConnectionString("DefaultConnection");
if(connectionString.StartsWith("mysql://"))
{
var conStr = connectionString.Substring("mysql://".Length);
services.AddDbContext<ApplicationDbContext>(options => options.UseMySql(conStr));
}
else
{
services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(connectionString));
}
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{