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

elb*_*aid 6 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.
Run Code Online (Sandbox Code Playgroud)

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

情况回顾

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

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

Kev*_*ang 5

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


elb*_*aid 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>
Run Code Online (Sandbox Code Playgroud)

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