unterstüzung für MySql;
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user