我有 2 个项目 A 和 B,
每个项目都有自己的数据库,并使用实体框架连接到它,每个项目单独运行良好
我的问题是,当我将项目 B 用作项目 A 中的库时,它给了我“类型(MYCLASS) 的初始化程序引发了异常"
你应该知道 (MYCLASS): 是项目 B 中的一个实体
问问题
10240 次
3 回答
3
检查两个项目是否在app.config
. 您可能在项目 B 中升级了 ef dll,但在项目 A 中没有升级。由于您在 A 中引用了 B,因此 entityframework 将 A 中的配置用于两个项目。
于 2012-11-06T09:14:19.470 回答
1
首先将相同版本的 EF 安装到所有项目,然后在 App.config 文件中检查以下内容,
- connectionStrings元素位于configSections元素之后。
- 启动元素在connectionStrings元素之后。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<connectionStrings>
<add name="SchedulingContext" connectionString="Data Source=XXX\SQL2008R2DEV;Initial Catalog=YYY;Persist Security Info=True;User ID=sa;Password=XXX" providerName="System.Data.SqlClient"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
于 2013-09-26T03:49:09.033 回答
0
只需从 ConfigSection 中删除所有行
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
于 2014-05-03T09:19:10.967 回答