Entity Framework core : DbContextOptionsBuilder' does not contain a definition for 'usesqlserver' and no extension method 'usesqlserver'

dbcontextoptionsbuilder usesqlserver example
dbcontextoptionsbuilder entity framework 6
entity framework core dbcontext dependency injection
dbcontextoptions entity framework 6
entity framework dbcontext dependency injection
dbcontext constructor
dbcontext onconfiguring connection string
dbcontextoptionsbuilder usemysql

I'm new to EF core and I'm trying to get it to work with my asp.net core project.

I get the above error in my startup.cs when trying confiugure the dbcontext to use a connection string from config. I'm following this tutorial : https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/intro

The problematic code in startup.cs :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SpaServices.Webpack;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
using tracV2.models;
using tracV2.data;

namespace tracV2
    public class Startup
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
            // Add framework services.


            string conn = Configuration.GetConnectionString("optimumDB");

            services.AddDbContext<tracContext>(options => options.usesqlserver(conn));

The usesqlserver method is recognized if I put it directly into the context :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

namespace tracV2.data
    public class tracContext : DbContext
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

All my reasearch online points to missing references, but I can't seem to find out which one i'm missing(see image).references

Any help would be greatly appreciated,


This is a known issue in the project system. See dotnet/project-system#1741

Configuring a DbContext, var optionsBuilder = new DbContextOptionsBuilder<BloggingContext>(); Read Getting Started on ASP.NET Core for more information on using EF with ASP. Sets the that the context should resolve all of its services from. EF will create and manage a service provider if none is specified. The service provider must contain all the services required by Entity Framework (and the database being used). The Entity Framework services can be registered using an extension method on . For example, the Microsoft SQL Server provider includes an

We install Microsoft.EntityFrameworkCore.SqlServer NuGet Package.


PM > Install-Package Microsoft.EntityFrameworkCore.SqlServer


   services.AddDbContext<AspDbContext>(options =>

Update do not forget to add using Microsoft.EntityFrameworkCore; namespace

Entity Framework core : DbContextOptionsBuilder' does not contain , context class in EF Core. public class SchoolContext : DbContext { public SchoolContext() { } protected override void OnConfiguring(​DbContextOptionsBuilder  Configures the runtime behavior of warnings generated by Entity Framework. You can set a default behavior and behaviors for each warning type. Note that changing this configuration can cause EF to build a new internal service provider, which may cause issues with performance. Generally it is expected that no more than one or two different configurations will be used for a given application

adding using Microsoft.EntityFrameworkCore;

manually solved the problem for me

Found that here


for dotnet core 3.1 add


Configuring a DbContext, This is a known issue in the project system. See dotnet/project-system#1741. For asp.net core version 2.1 make sure to add the following package to fix the problem. (At least this fix the issue using SQLite) dotnet add package Microsoft.EntityFrameworkCore.Sqlite dotnet add package Microsoft.EntityFrameworkCore.Design Here is the reference of the documentation using SQLite with entity framework core.

Install below NuGet Package will solve your issue


Install-Package Microsoft.EntityFrameworkCore.SqlServer

Connection Strings in Entity Framework Core, Exception message: 'DbContextOptionsBuilder' does not contain a definition for EntityFrameworkCore has not added the Microsoft. Entity Framework core : DbContextOptionsBuilder' does not contain a definition for 'usesqlserver' and no extension method 'usesqlserver' asp.net-core entity-framework-core

I was using Visual Studio Code.

1) Try to install the package 'Microsoft.EntityFrameworkCore.SqlServer' by specifying the version number.

VS Code:

'dotnet add package Microsoft.EntityFrameworkCore.SqlServer -v 1.1.1'

Visual Studio:-

'Install-Package Microsoft.EntityFrameworkCore.SqlServer -v 1.1.1'

Refer the link 'Package 'Microsoft.EntityFrameworkCore.SqlServer' is incompatible with 'all' frameworks in the project' for doing it.

2) Then add the namespace 'using Microsoft.EntityFrameworkCore;' manually in the Startup.cs file.

Refer the below link https://github.com/aspnet/EntityFramework/issues/7891.

3) If you get any dependency issue for 'Microsoft.EntityFrameworkCore.SqlServer.Design', like "Package 'Microsoft.EntityFrameworkCore.Design' is incompatible with 'all' frameworks in project" ,we need to run the below command,

VS Code:-

dotnet add package Microsoft.EntityFrameworkCore.Design -v 1.1

Visual Studio

Install-Package Microsoft.EntityFrameworkCore.Design -v 1.1

Entity Framework Core DbContext, NET Core application of some sorts. You'll do this like shown below: using Microsoft.EntityFrameworkCore; using System; namespace  The DBContext is heart of the Entity Framework. It is the connection between our entity classes and the database. The DBContext is responsible for the database interactions like querying the database and loading the data into memory as entity. It also tracks the changes made to the entity and persists the changes to the database.

[SOLVED], DbContextOptionsBuilder. We build DBContext options using the DbContextOptionsBuilder API. There are two ways  In this post, we will see how to configure DbContext in Entity framework EFCore in ASP.NET Core. As we looked into our article on Repository implementation for Entity framework DbContext instance represents Unit Of Work and Repository patterns which can be used to query from a database and perform CRUD operations.

UseSqlServer() method is missing from Microsoft , Entity Framework Core does not support multiple parallel operations being run on the same DbContext instance. This includes both parallel execution of async queries and any explicit concurrent use from multiple threads. Therefore, always await async calls immediately, or use separate DbContext instances for operations that execute in parallel.

Solving: 'DbContextOptionsBuilder' does not contain a definition for , Entity Framework Core. Configures the context to connect to a Microsoft SQL Server database. Configures the context to connect to a Microsoft SQL Server database. Configures the context to connect to a Microsoft SQL Server database. Configures the context to connect to a Microsoft SQL Server database. UseSqlServer (DbContextOptionsBuilder