Raas Masood
Raas Masood

Reputation: 1575

Entity Framework 6 not recognizing AddSqlServer()

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?

Upvotes: 4

Views: 4735

Answers (4)

Hardik Chudasama
Hardik Chudasama

Reputation: 81

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.

Upvotes: 3

Avi Cherry
Avi Cherry

Reputation: 4096

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.

Upvotes: 1

Matt DeKrey
Matt DeKrey

Reputation: 11942

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.

Upvotes: 1

ErikEJ
ErikEJ

Reputation: 41799

EF6 is a very different framework from EF7, and does not have a UseSqlServer extension method.

Upvotes: 1

Related Questions