Cannot override OnConfiguring in beta5 - no suitable method found to override

本小妞迷上赌 提交于 2019-12-08 13:44:30

问题


After updating EF7 to beta5 from beta4 my OnConfiguring stopped working.

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

I can't figure out what I need to write instead.

Here's my project.json, just in case

{
    "dependencies": {
        "EntityFramework.SqlServer": "7.0.0-beta5",
        "EntityFramework.Commands": "7.0.0-beta5",
        ...
    }
}

it doesn't have "EntityFramework": "7.0.0-beta4" (no beta5 yet). It apparently isn't needed.

DNVM list

Active Version           Runtime Architecture Location                      Alias
------ -------           ------- ------------ --------                      -----
       1.0.0-beta4       clr     x64          C:\Users\Snebjorn\.dnx\runtimes
       1.0.0-beta4       clr     x86          C:\Users\Snebjorn\.dnx\runtimes
       1.0.0-beta4       coreclr x64          C:\Users\Snebjorn\.dnx\runtimes
       1.0.0-beta4       coreclr x86          C:\Users\Snebjorn\.dnx\runtimes
  *    1.0.0-beta5       clr     x86          C:\Users\Snebjorn\.dnx\runtimes default
       1.0.0-beta5-12103 clr     x86          C:\Users\Snebjorn\.dnx\runtimes

回答1:


You need to use EntityOptionsBuilder in beta 5 (and back to DbContextOptionsBuilder in beta 6)




回答2:


Couldn't get OnConfiguring to work.

But now this works

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddEntityFramework()
            .AddSqlServer()
            .AddDbContext<ApplicationDbContext>(opt => opt.UseSqlServer("..."));
    }
}

It didn't in beta4.

NB. Remember to add using Microsoft.Data.Entity;




回答3:


If you are using EF 7.0.0-beta7 the method signature looks thusly:

protected internal virtual void OnConfiguring(DbContextOptions options);


来源:https://stackoverflow.com/questions/31336007/cannot-override-onconfiguring-in-beta5-no-suitable-method-found-to-override

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!