实体框架连接问题 [英] EntityFramework Connection problem

查看:101
本文介绍了实体框架连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Visual Studio 2008中有3个项目的解决方案。一个Web应用程序和2个类库。实体框架模型在一个类库中,启动项目是Web应用程序。



我曾经遇到这个问题:



在配置中找不到指定的命名连接,不适用于EntityClient提供者,或无效。



我已修复它将连接字符串从实体模型所在的类库的App.config复制到web应用程序的web.config(启动项目)。



I发现在这里发布的解决方法:
连接字符串和实体框架问题



但我的问题是:我如何避免使用web.config中的连接字符串,并使用实体模型所在的app.config中的连接字符串?



非常感谢。

解决方案

我建议复制连接字符串。这是.Net配置工作。每个可执行应用程序有一个App.config。在您的情况下,正在运行的Web应用程序的Web.config。



您可以将EF项目中的app.config嵌入到程序集中,在执行的程序集中读取它连接字符串并使用重载的构造函数...但保留版本1: - )


I have a solution in Visual Studio 2008 with 3 projects. One Web Application and 2 class libraries. The entity framework model is in a class library and the start project is the web application.

I used to have this problem:

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

I fixed it copying the connection string from the App.config of the class library where the entity model is located to the web.config of my web application (start project).

I found that workaround posted here: Problem with connectionstring and entityframework

But my question is: ¿how can i avoid using the connection string from the web.config and use the one from the app.config where the entity model is located?

Thank you very much.

解决方案

I'd suggest to copy the connection string. this is .Net configuration works. Per executable application there is one App.config. In your case the Web.config of your web application that's running.

You could embed the app.config from the EF project into the assembly extract it in your executing assembly read the connection string and use the overloaded constructor... but stay with version 1 :-)

这篇关于实体框架连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆