EF Core for MySql踩坑(一)
1.链接字符串
"ConnectionStrings": {
"ExamOnlineCon": "server=localhost;user id=root;password=root;database=ExamOnlineDb;charset=utf8;sslMode=None"
},
2.上下文Context
3.注册服务
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<MySqlContext>(options =>
options.UseMySql(Configuration.GetConnectionString("ExamOnlineCon")));
services.AddControllersWithViews();
}
4. 映射数据库
说一下,第三个 " Microsoft.Extensions.Logging.Debug "不用添加
做Code First 映射的时候发现报错了
Method 'get_Info' in type 'MySql.Data.EntityFrameworkCore.Infraestructure.MySQLOptionsExtension' from assembly 'MySql.Data.EntityFrameworkCore, Version=8.0.19.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' does not have an implementation.
上网搜了下资料解释为
不支持 .net core 3.1 的映射,解决办法就是用的这个驱动包
鲸落于海,星沉于洼,风隐于密林,蝉鸣漏进夏至,想让世间所有温柔住进你眼里