问题
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