find and solve || findandsolve.com
Please wait.....

DbContextOptionsBuilder does not contain a definition for UseSqlServer and no accessible extension method UseSqlServer accepting a first argument of type DbContextOptionsBuilder

DbContextOptionsBuilder does not contain a definition for UseSqlServer and no accessible extension method UseSqlServer accepting a first argument of type DbContextOptionsBuilder

'DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer' and no accessible extension method 'UseSqlServer' accepting a first argument of type 'DbContextOptionsBuilder' could be found (are you missing a using directive or an assembly reference?).

public void ConfigureServices(IServiceCollection services)
{
  options => options.UseSqlServer("name=ConnectionStrings:DefaultConnection"));
}

Answer


Option 1.

If you are using EntityFrameworkCore you must do something like that.

Install package from nuget:

Microsoft.EntityFrameworkCore.SqlServer

 or

Add to source file:

using Microsoft.EntityFrameworkCore

Option 2.

First we install the Microsoft.EntityFrameworkCore.SqlServer NuGet Package from command mode like that:

PM > Install-Package Microsoft.EntityFrameworkCore.SqlServer

Then, after importing the namespace with:

using Microsoft.EntityFrameworkCore;

and add the database context  like as:

services.AddDbContext<DbContext>(options =>
    options.UseSqlServer(config.GetConnectionString("yourconnectionstring")));

Option 3.

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

Option 4.

Double click on your main project and copying the following code into the yourmani.csproj.

 <Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />   </ItemGroup>
</Project>

Mahira  khanna

Mahira khanna

I have the skills you need for you company blog, website, or other content materials

Comments



Report Response