ef core(code first) 通用性迁移步骤

  1. 创建Models类
  2. 创建DbContext派生类
  3. 添加Provider的nuget包,这里以mysql为例:
    1. Pomelo.EntityFrameworkCore.MySql
    2. Pomelo.EntityFrameworkCore.MySql.Design
  4. 在dbcontext的OnConfiguring重写方法中添加

    if (!optionsBuilder.IsConfigured)
    {
    #warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
    optionsBuilder.UseMySql(ConnectString);
    }

    1. 在其它地方配置也可以,比如在AspNetCore项目中,通常在Startup类中配置
  5. dotnet ef migrations add {migration name} -p {dbcontext project} -s {host startup project}
  6. dotnet ef database update -p {dbcontext project} -s {host startup project}

你可能感兴趣的:(ef)