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;

时间: 2024-10-20 08:48:30

No database provider has been configured for this DbContext的相关文章

SQLite EF Core Database Provider

原文链接 This database provider allows Entity Framework Core to be used with SQLite. The provider is maintained as part of the Entity Framework Core project. Supported Database Engines SQLite (3.7 onwards) Supported Platforms .NET Framework (4.5.1 onward

一步步学习EF Core(1.DBFirst)

前言 很久没写博客了,因为真的很忙,终于空下来,打算学习一下EF Core顺便写个系列, 今天我们就来看看第一篇DBFirst. 本文环境:VS2017  Win7  .NET Core1.1    EF Core1.1.2 正文 这里我们不讨论是用DBFirst好,还是CodeFirst高端..各有各自的用处和适用场景.. 我们单纯的只是来使用这个DBFirst.. 既然是DBFirst,那么在用DBFirst之前..首先你要有一个数据库(嗯,废话) 其次,如果你是Windows7系统 那么需

Configuring and troubleshooting a Schema Provider

原文:https://codesmith.atlassian.net/wiki/display/Generator/Configuring+and+troubleshooting+a+Schema+Provider The sections below will help guide you through using and configuring various Schema Providers that ship with CodeSmith Generator. Creating a n

Cannot obtain the required interface (&quot;IID_IDBCreateCommand&quot;) from OLE DB provider &quot;OraOLEDB.Oracle&quot; for linked server xxxx

  今天遇到了一个关于LINKED SERVER查询报错的案例,链接服务器链接ORACLE数据库,测试没有错误,但是执行脚本的时候,报如下错误: Msg 7399, Level 16, State 1, Line 1 The OLE DB provider "OraOLEDB.Oracle" for linked server "xxxx" reported an error. Access denied. Msg 7301, Level 16, State 2,

uninstall 11.2.0.3.0 grid &amp; database in linux 5.7

OS: Oracle Linux Server release 5.7 DB: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production 1.以oracle用户登录启动dbca [[email protected] ~]# su - oracle [[email protected] ~]$ dbca 会逐一删除所有节点的database 2.用oracle用户登录并在cd $ORACLE_HOME/

mssql2008R2 RCU-6083:ALTER database FWC SET READ_COMMITTED_SNAPSHOT ON

RCU-6083:失败 - 检查所选组件的先决条件要求:MDS 有关详细资料, 请参阅 E:\Setup\ofm_rcu\rcu\log\logdir.2014-11-27_12-39\rcu.log 中的 RCU 日志.------------------------------------------------------------------------------Component     : MDSError         : Repository creation check

Entity Framework Database/Code First实现对表进行压缩配置

我采用Database First,用Sql很容易就可以做到对一个表进行压缩.如以下: CREATE TABLE [dbo].[Entities]( [Id] [int] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](max) NULL, Primary Key Clustered ([Id] ASC) WITH (DATA_COMPRESSION=PAGE) ); 遗憾的是当我采用Database First反向之后.再利用反向后的DbContext(我命

Asp.Net MVC EF之一:使用Database类在EF框架中执行Sql语句

h4 { padding: 8px 5px; background-color: #32c5d2 } .start-box,.body { padding: 10px } .tit { font-size: 14px; font-weight: bold } div.content { line-height: 150%; font-weight: bold } .content { border: dashed 1px #999999; padding: 10px; background: #

【译著】Code First :使用Entity. Framework编程(6)

小分享:我有几张阿里云优惠券,用券购买或者升级阿里云相应产品最多可以优惠五折!领券地址:https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=ohmepe03 Chapter6 Controlling Database Location,Creation Process, and Seed Data 第6章 控制数据库位置,创建过程和种子数据 In previous chapters you have