mysql ef efcore set
mysql ef6
app.config web.config
<add name="CusDbContext" connectionString="Data Source=ip;port=3306;Initial Catalog=dbname;uid=uname;password=pwd;Convert Zero Datetime=True" providerName="MySql.Data.MySqlClient" />
[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class DbContext : DbContext
{}
mysql ef core mvc
using Microsoft.EntityFrameworkCore;
using MySQL.Data.EntityFrameworkCore;
...
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddDbContext<CusDbContext>(options=>options.UseMySQL(Configuration.GetConnectionString("CusDbContext")));
}
appsettings.json配置
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"CusDbContext": "Server=ip;Initial Catalog=dbname;uid=uname;password=pwd;Allow User Variables=True;sslMode=None"
}
}
配完上面的,再nuget命令中迁移db
add-migration initdb
update-database -verbose
ok!
install-package Pomelo.EntityFrameworkCore.MySql
加入种子数据会报错:
An exception has been raised that is likely due to a transient failure. Consider enabling transient
办法:
ConnectionStrings中CusDbContext连接加入:
sslMode=None;
iis安装,汗!
控制面板\程序\启用或关闭windows功能,
然后找iis,完成后在edge输入localhost有响应则成功。