No database provider has been configured for this DbContext


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;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM