如何在使用edmx文件时在连接字符串中指定元数据位置 [英] How to specify metadata location in connection string when using an edmx file

查看:89
本文介绍了如何在使用edmx文件时在连接字符串中指定元数据位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有在edmx文件中定义的数据模型的Web项目。连接字符串开始如下:



metadata = res:// * /;



一段时间。但是在项目上工作的其他人创建了一个dll,它也使用实体框架并将其添加到bin文件夹。现在当我尝试创建我的连接时,加载元数据时出错。



除了完全改变我们一个人或两个人在做事情的方式外,我想知道如果我的连接字符串可以更改为仅查找我的edmx文件中定义的元数据。问题是,对于我的生活,我找不到正确的语法来做到这一点。元数据嵌入在输出程序集中,因此没有要指向的物理元数据文件。我应该如何在连接字符串中指定元数据位置?

解决方案

是的,我以前看过这个问题。而且只有在有人问这个问题之前才是时间问题。



基本上 res:// * / load所有程序集中的所有元数据,所以如果有多个元数据集EF被困惑。



所以使用 res:// * / 默认情况下,EF在WebApplications中是一个错误,不幸的是一个我们没有时间解决的问题。



解决方法是通过连接字符串获得更具体的内容:
res:// /App_Code.Northwind.csdl|res:// /App_Code.Northwind.ssdl|res://*/App_Code.Northwind.msl;



App_Code是App_Code文件夹(假设您的模型在您的Web项目中),而Northwind是您的EDMX的名称。如果您在使用名称时遇到问题,请使用Reflector类似的方式查看程序集中的资源名称。



这样做会告诉EF哪个CSDL,SSDL和MSL从加载的程序集加载并解决您的问题。



希望这有助于



Alex


I have a web project with a data model defined in an edmx file. The connection string starts like this:

metadata=res://*/;

This has worked fine for a while. But somebody else working on the project created a dll that also uses the entity framework and added it to the bin folder. Now when I try to create my connection there is an error loading the metadata.

Aside from totally changing the way one or both of us is doing things, I wonder if the problem can be fixed if my connection string can be changed to only look for the metadata defined in my edmx file. The problem is, for the life of me I can't find the right syntax to do this. The metadata is embedded in the output assembly, so there are no physical metadata files to point to. How exactly should I specify the metadata location in the connection string?

解决方案

Yes I've seen this problem before. And it was only a matter of time before someone asked this question.

Basically res://*/ loads all the metadata in all assemblies, so if there is more than one set of metadata EF gets confused.

So using res://*/ by default as EF does in WebApplications is a bug, unfortunately it is one that we didn't have time to resolve.

The workaround is to get more specific with the connection string something like this: res:///App_Code.Northwind.csdl|res:///App_Code.Northwind.ssdl|res://*/App_Code.Northwind.msl;

Where App_Code is the App_Code folder (assuming that is where your model is in your web project), and Northwind is the name of your EDMX. If you are having trouble getting the names to use, look at the resource names in your assembly using something like Reflector.

Doing this tells the EF exactly which CSDL, SSDL and MSL to load from the loaded assemblies and should resolve you problem.

Hope this helps

Alex

这篇关于如何在使用edmx文件时在连接字符串中指定元数据位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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