问题
I am trying to use EF6 with VS2015 CTP and ASP.NET MVC 6. it is not recognizing the below mentioned code in startup.cs
which I added when I was using EF7.
public void ConfigureServices(IServiceCollection services)
{
services.AddEntityFramework(Configuration)
.AddSqlServer()
.AddDbContext<VNDBContext>(options => options.UseSqlServer(Configuration.Get("Data:VNDBContext:ConnectionString")));
services.AddMvc().Configure<MvcOptions>(options =>
{
var jsonFormatter = (JsonOutputFormatter)options.OutputFormatters
.Where(o => o.Instance.GetType() == typeof(JsonOutputFormatter)).First().Instance;
jsonFormatter.SerializerSettings.ReferenceLoopHandling =
ReferenceLoopHandling.Ignore;
});
services.AddSingleton<INodeService, NodeService>();
}
If I use EF7 it has other issues as it is not matured yet.
How can I set above mentioned setting while doing everything in MVC6 but with EF6?
回答1:
As @ErikEJ mentions in his answer, EF6 is very different from EF7 and does not have any utilities for working in the Startup.cs. However, that is not to say it's not possible; I'm doing it with my own project with a line similar to the following:
services.AddTransient<MyEf6DbContext>(sp => new MyEf6DbContext(Configuration.Get("Data:VNDBContext:ConnectionString")));
This allows you to use MyEf6DbContext
injected into your controllers and other services just as you'd expect! You'll have to do some more work to get Identity 3 and such to work with EF6, but they're all very pluggable.
回答2:
EF6 is a very different framework from EF7, and does not have a UseSqlServer extension method.
回答3:
Actually, you can use EF6 with dnx451 and MVC6, which gives you access to all of the new APIs. EF6 is not designed out of the box, though, to work with the new DependencyInjection system, so you'll need to configure it yourself. Also, migrations won't work at all. I wrote some replacement 'k/dnx' commands that can handle migrations the same way that the EF7 project does.
回答4:
Actually with the latest update they have changed it a bit! they renamed the package to EntityFramework.MicrosoftSqlServer Try searching with that in the nuGet manager and you will get all the methods you are looking for.
来源:https://stackoverflow.com/questions/29568924/entity-framework-6-not-recognizing-addsqlserver