Gillardo
Gillardo

Reputation: 9828

UseSqlServer method missing MVC 6

I am trying to implement Entity Framework 7 in MVC 6, and on this page here it says to do

services.AddEntityFramework()
    .AddSqlServer()
    .AddDbContext<MusicStoreContext>(options =>
                        options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

But for me, the UseSqlServer method isn't visible? Anyone know how to make it visible? Or is this an old way of configuring entity framework?

My startup.cs file looks like this

using FluentValidation;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection;

namespace me.namespace.project
{
    public class Startup
    {
        public static IConfiguration Configuration { get; set; }

        public Startup(IHostingEnvironment env)
        {
            // Setup configuration sources.
            Configuration = new Configuration()
                .AddJsonFile("config.json")
                .AddEnvironmentVariables();
        }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            // entity framework
            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<DataContext>();

        }
    }
}

Upvotes: 39

Views: 33078

Answers (5)

Mohamed Bedawy
Mohamed Bedawy

Reputation: 1

install the following package Microsoft.EntityFrameworkCore.SqlServer version 6.0.24 Microsoft.EntityFrameworkCore.SqlServer it's working for me

Upvotes: 0

PARAG DESHMUKH
PARAG DESHMUKH

Reputation: 219

It's a NuGet Packages Problem

Install the following Packages and with its Proper Versions

 1.  Microsoft.EntityFrameworkCore(Latest Version)
 2.  Microsoft.EntityFrameworkCore.SqlServer(1.0.4 Version)

Upvotes: 22

DavidG
DavidG

Reputation: 119066

UseSqlServer is an extension method in the namespace Microsoft.Data.Entity so you need to import that in your code, like this:

using Microsoft.EntityFrameworkCore;

Upvotes: 40

Timur Lemeshko
Timur Lemeshko

Reputation: 2879

Install Microsoft.EntityFrameworkCore.SqlServer 1.0.1 package works for me Version of Microsoft.EntityFrameworkCore is 1.1.0

Upvotes: 48

Anastasiosyal
Anastasiosyal

Reputation: 6626

Since this has been posted, assemblies have been renamed. As part of EntityFrameworkCore you now need to add a using statement the following

using Microsoft.EntityFrameworkCore;

And the .UseSqlServer extension method to configure your context will become available

Upvotes: 28

Related Questions