我最近将项目更新为最新版本的Entity Framework Core(+ VS2017)。当我尝试更新数据库时,出现以下错误消息。错误消息很明显,但似乎是错误的。我的ConfigureServices中有AddDbContext(请参阅下面的代码)。没有为此DbContext配置数据库提供程序
我错过了什么?
错误
> dotnet ef database update --verbose
Finding DbContext classes...
Using context 'ApplicationDbContext'.
System.InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.
启动
public void ConfigureServices(IServiceCollection services) {
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(this.Configuration.GetConnectionString("DefaultConnection")));
的csproj
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore">
<Version>1.1.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore">
<Version>1.1.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer">
<Version>1.1.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design">
<Version>1.1.0</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools">
<Version>1.0.0-msbuild1-final</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design">
<Version>1.1.0</Version>
</PackageReference>
你的连接字符串是什么样的? – DavidG
并且你的上下文在其构造函数中有'DbContextOptions'对象吗? –
DavidG
这是连接字符串。我可以通过SSMS连接到它。 “DefaultConnection”:“Server =(localdb)\\ mssqllocaldb; Database = aspnet -MG-5880417d-c8ef-4bc8-afc5-4a7f7c617d9b; Trusted_Connection = True; MultipleActiveResultSets = true” – Martin