[英]Entity Framework - The migrations configuration type was not be found in the assembly
[英]configuration of entity framework in dependent assembly
我有个问题。 我想将访问数据库的所有逻辑隐藏在单独的程序集中。 但是,第一次调用数据库时,应用程序因错误而崩溃
EntityFramework.dll中出现“类型为System.InvalidOperationException的异常”,但未在用户代码中处理
有关更多信息:对于具有不可更改名称“ System.Data.SqlClient”的ADO.NET提供程序,找不到提供程序实体框架。 确保供应商已在“ entityFramework”应用程序配置文件部分中注册。 有关更多信息,请参见。 页面http://go.microsoft.com/fwlink/?LinkId=260882 。 ”
在相关程序集的配置文件中指定的所有供应商和连接字符串。 在msdn中,我读到所有配置都必须在config可执行程序集中注册。 但是在这种情况下,有必要将EF拉入主组件,这不应
其实是问题。 如何使用Ef配置进入依赖程序集?
如您在MSDN链接中所述,配置应驻留在可执行应用程序(web.config,app.config)中。 您的类库仅包含代码,并且当从可执行项目引用时,仅复制和使用.dll文件。 因此,即使您在类库项目的app.config中填写了配置,也不会使用数据。
另一方面,您唯一需要做的就是将配置信息包含在可执行配置文件中。 如果不需要,则无需在那里引用EF。 考虑一下,好像您自己的dll需要某些配置才能存在于配置文件中一样,在这种情况下是EF节,但可能是任何其他事情。
您的配置文件应如下所示:
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
...
</configSections>
...
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
<connectionStrings>
<add name="DefaultConnection" connectionString="..." providerName="System.Data.SqlClient" />
</connectionStrings>
...
</configuration>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.