'DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer'

asp.net-core asp.net-mvc asp.net-web-api entity-framework mysql

Question

In VS 2015 Pro (Update 3), I'm attempting to develop a Web API in C# that targets.NET Core.

I'm following these instructions: zzzz-9 zzzz. I'm not sure how much of a difference it makes because I'm connecting to a MySQL database rather than a SQL Server database, however.

However, I have to My context is registered using dependency injection. in the tutorial, therefore I must ConfigureServices the following line to the Startup.cs file's ConfigureServices section:

var connection = Configuration.GetConnectionString("DefaultConnection");
services.AddDbContext< Models.PropWorxContext > (options => options.UseSqlServer(connection));;

However, VS displays the following error:

Error CS1061 There is no definition for "UseSqlServer" in "DbContextOptionsBuilder," and no extension method taking a first parameter of type "DbContextOptionsBuilder" could be located (maybe you lack a using directive or an assembly reference?)

Do you know why?

The Startup.cs file as a whole looks like this:

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace PropWorxAPI
{
    public class Startup
    {
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                .AddEnvironmentVariables();
            Configuration = builder.Build();
        }

        public IConfigurationRoot Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();

            var connection = Configuration.GetConnectionString("DefaultConnection");
            services.AddDbContext< Models.PropWorxContext > (options => options.UseSqlServer(connection));
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseMvc();
        }
    }
}

Using the Package Manager, I also installed the MySQL package, and now my project.json file has the following entry:

*"MySql.Data.EntityFrameworkCore": "7.0.6-IR31"*

I've spent the whole day trying to figure things out, so any pointers as to where I went wrong would be much appreciated:( I appreciate it.

1
10
10/31/2016 12:23:53 PM

Accepted Answer

ZZZ_tmp
30
10/31/2016 12:57:21 PM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow