我试图在一个EFCache 4.5项目中使用NuGet包(https://github.com/moozzyk/EFCache),并在启动时遇到以下错误:
System.InvalidOperationException
HResult=0x80131509
Message=The Entity Framework provider type '
EFCache.CachingProviderServices, EFCache, Version=1.1.3.0,
Culture=neutral, PublicKeyToken=46c4868af4307d2c' did not have a static
property or field named 'Instance'. Entity Framework providers must
declare a static property or field named 'Instance' that returns the
singleton instance of the provider.System.Data.Entity.Core.Common.DbProviderServices,扩展了EFCache.CachingProviderServices,它没有静态实例属性。因此,似乎在所有情况下,这种财产都不一定存在。
看看EFCache.CachingProviderServices的代码,我看不出它有一个静态实例属性的任何明智的方法,因为它的目的是充当另一个作为构造函数参数传递的DBProviderServices实例的包装器。
让EFCache使用实体框架的人对发生了什么事有什么想法吗?
EFCache版本为1.1.3.0。我在使用实体框架6.1.0和6.2.0时也看到了同样的问题。Web.config部分如下所示:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="EFCache.CachingProviderServices, EFCache" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
发布于 2019-05-05 09:47:47
此问题是由配置文件中的以下行引起的:
<provider invariantName="MySql.Data.MySqlClient" type="EFCache.CachingProviderServices, EFCache" />它应该描述实际的db提供程序,对于MySQL,它通常如下所示:
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.11.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />通常,如链接页面中所述,EFCache.CachingProviderServices是包装提供程序,因此它不应该(也不能)注册为常规数据库提供程序(这要求它们提供异常中提到的静态Instance属性/字段)。
相反,它必须通过自定义DbConfiguration或静态EntityFrameworkCache.Initialize()方法激活,如如何使用它中所解释的那样。
https://stackoverflow.com/questions/55988018
复制相似问题