4

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

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

1

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

2 Comments

so is it just not possible to use EF6 with mvc 6 in vs2015?
I imagine it should be, if you target .net 4.5, but of course you cannot use any new apis!
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.