如何让多个项目访问相同的Entity Framework项目?

时间:2010-04-27 20:27:43

标签: entity-framework

好的,这个问题已被多次询问过。只需用Google搜索错误消息:

The specified named connection is either not found in the configuration,
not intended to be used with the EntityClient provider, or not valid.

我在论坛,帮助网站和博客上尝试过所有建议......没有用!

情况回顾

我正在将解决方案分成三个不同的项目:一个用于我的EF4模型,一个WinForm和一个ASP.NET MVC Web应用程序。我的连接字符串和配置有问题。

是否有使用VS2010 / EF4 / .NET Framework 4.0的更新解决方案?

2 个答案:

答案 0 :(得分:5)

不确定,但您可能需要将EF4项目的app.config文件中的Entity Framework配置部分移动到WinForm app.config和ASP.NET MVC web.config文件中。

答案 1 :(得分:3)

真的,答案是复制其他项目的配置文件中的<connectionStrings>部分,如上所述。

<connectionStrings>
    <add name="DataEntities" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=xxx;Initial Catalog=xxx;User Id=xxx;Password=xxx;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

所以,这与我之前在许多网站上看到的答案相同。事实上,它从一开始就工作,但我有另一个错误(“配置系统无法初始化”),所以我认为它是app.config中连接字符串的错误值。事实上,app.config是有效的,但只是移动底部的部分解决了这个问题...奇怪的?

相关问题