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 的映射,解決辦法就是用的這個驅動包

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章