码迷,mamicode.com
首页 > 数据库 > 详细

No database provider has been configured for this DbContext

时间:2016-09-07 14:33:18      阅读:748      评论:0      收藏:0      [点我收藏+]

标签:

var context = ((IInfrastructure<IServiceProvider>)set).GetService<DbContext>();

在EF Core 1.0 中会出现如下错误

Unhandled Exception: 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.

解决方案:

var context = ((IInfrastructure<IServiceProvider>)set).GetService<ICurrentDbContext>().Context;

No database provider has been configured for this DbContext

标签:

原文地址:http://www.cnblogs.com/gilchen/p/5849143.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!