从单独的程序集使用EF时出错 [英] error using EF from separate assembly
本文介绍了从单独的程序集使用EF时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨大家,
我用EF做了我的第一步。当从包含它和EDM的程序集中访问objectcontext时,一切正常。
但是现在我创建了一个单独的winform-app并试图使用驻留在另一个DLL中的EF功能我得到一个错误告诉我要么无法在配置文件中找到连接,或者它不适合与EntityClient提供商一起使用。
如何解决此问题?
来自柏林的问候语bolek75
Hi folks,
I do my first steps using EF. When accessing the objectcontext from within the assembly containg it and the EDM all works fine.
But now I created a separate winform-app and trying to use the EF functionality residing in anonother DLL I get an error telling me that either the connection could not be found in the config-file or it is not suited for use with the EntityClient provider.
What to do to fix this problem?
Greets from Berlin
bolek75
推荐答案
最简单的事情(我记得),将EF连接字符串放在你的单独应用程序的app.config中。
我记得,当你添加一个新的EF模型时,它会创建一个连接字符串(EF)并将其放在托管EF模型的项目的app.config中。然后,当您尝试从不同的程序集创建ObjectContext时,它找不到连接字符串。
但是,我怀疑这对您来说是一个很好的长期解决方案(就像你一样)为了生产目的,可能需要更改连接字符串,因此您也可以使用接受连接字符串的ObjectContext构造函数。但是,作为警告,EF连接字符串可能有点痛苦。我相信有一个< x> Builder对象。 EntityConnectionBuilder可能吗?
HTH,
The simplest thing to do (as I recall), is put the EF connection string in the app.config of your seperate app.
As I recall, when you add a new EF model, it creates a connection string (EF) and places it in the app.config of the project which hosts the EF model. Then, when you try to create the ObjectContext from a different assembly, it can't find the connection string.
However, I rather doubt that this will be a good long term solution for you (as you'll probably need to change the connection string for production purposes), so you can also use the ObjectContext constructor that accepts a connection string. As a warning, however, the EF connection string can be a bit of a pain. I believe there is a <x>Builder object. EntityConnectionBuilder maybe?
HTH,
Chris
这篇关于从单独的程序集使用EF时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文