【问题标题】:.NET Core 1.1 in VS2017: DbContextOptionsBuilder does not contain a definition for 'UseSqlServer'VS2017 中的 .NET Core 1.1:DbContextOptionsBuilder 不包含“UseSqlServer”的定义
【发布时间】:2017-08-05 09:35:47
【问题描述】:

在 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>

【问题讨论】:

  • 噢!你说得对。我想我刚刚习惯了 VS2015,它提供了在抛出错误时添加这些引用的选项。谢谢亨克!
  • 我会给出答案,这样我们就可以关闭它了。或者您可以删除问题。

标签: asp.net-core visual-studio-2017 asp.net-core-1.1


【解决方案1】:

我必须从 NuGet 安装“Microsoft.EntityFrameworkCore.SqlServer”。

在我运行的包管理器控制台中:Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 1.1.2

我还必须确保在 Startup.cs 文件中使用 using 语句引用了 Microsoft.EntityFrameworkCore:using Microsoft.EntityFrameworkCore;

【讨论】:

    【解决方案2】:

    正如错误所说,

    ...(您是否缺少 using 指令或程序集引用?)

    这是一种扩展方法,所以你需要using Microsoft.EntityFrameworkCore;

    【讨论】:

    • 一个点扩展方法如何 - 这让我一直很沮丧 - 最令人沮丧?
    猜你喜欢
    • 2017-11-25
    • 2017-03-13
    • 2021-08-03
    • 2020-06-17
    • 2021-12-17
    • 1970-01-01
    • 2017-08-23
    • 2022-11-30
    相关资源
    最近更新 更多