【发布时间】:2017-09-30 04:36:36
【问题描述】:
我刚刚安装了 Visual Studio 17,我想使用 mysql 作为我的数据库来开发 WebAPI。
我的 csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<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.EntityFrameworkCore" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="1.1.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
</ItemGroup>
</Project>
我从 NuGet 包管理器安装了 Pomelo.EntityFrameworkCore.Mysql。
我的 aspsettings.json:
{
"ConnectionStrings": {
"MysqlConnection": "server=localhost;userid=root;pwd=root;port=3306;database=aspnet;sslmode=none;"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}
在 ConfigureServices() 内的 strtup.cs 中,我有:
services.AddDbContext<WebAPIDataContext>(options =>
{
options.UseMySQL(Configuration.GetConnectionString("MysqlConnection")); }
);
services.AddMvc();
services.AddScoped<IProfileRepository, ProfileRepository>();
但是,它给了我DBContextOptionsBuilder does not contain a definition for UseMyQL 错误。为什么会这样?
【问题讨论】:
标签: asp.net-core entity-framework-core visual-studio-2017