在VS2017中处理一个新项目,但是当我为dbContext输入我的服务时,我收到此错误:
Error CS1061 'DbContextOptionsBuilder' does not contain a definition for
'UseSqlServer' and no extension method 'UseSqlServer' accepting a first
argument of type 'DbContextOptionsBuilder' could be found (are you missing a
using directive or an assembly reference?)
Microsoft.EntityFrameworkCore.SqlServer v1.1.1是否不再包含此功能或我遗失了什么?
的.csproj
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<PackageTargetFallback>$(PackageTargetFallback);portable-
net45+win8+wp8+wpa81;</PackageTargetFallback>
<ApplicationIcon />
<OutputTypeEx>exe</OutputTypeEx>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore"
Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1"
/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design"
Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer"
Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design"
Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools"
Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug"
Version="1.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink"
Version="1.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design"
Version="1.1.0" />
<PackageReference Include="Novell.Directory.ldap.netstandard"
Version="2.3.6" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference
Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services" />
</ItemGroup>
</Project>
答案 0 :(得分:3)
就像错误一样,
...(您是否缺少using指令或程序集引用?)
这是一种扩展方法,因此您需要using Microsoft.EntityFrameworkCore;
答案 1 :(得分:2)
我必须安装&#39; Microsoft.EntityFrameworkCore.SqlServer&#39;来自NuGet。
在程序包管理器控制台中,我运行了Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 1.1.2
我还必须确保在Startup.cs文件中使用using语句引用Microsoft.EntityFrameworkCore:using Microsoft.EntityFrameworkCore;
。