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

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

问题描述

我有在EDMX文件中定义的数据模型的Web项目。连接字符串开头是这样的:

=元数据资源:// * /;

这一段时间工作的罚款。但别人的项目创建工作也使用实体框架的dll并将其添加到bin文件夹。现在,当我尝试创建我的连接有错误加载的元数据。

除了完全改变的方法之一或两者我们正在做的事情,我不知道这个问题可以是固定的,如果我的连接字符串可以改变只能看在我的EDMX文件中定义的元数据。问题是,我的生命,我找不到正确的语法来做到这一点。元数据被嵌入在输出组件,所以有没有物理元数据文件,以指向。我究竟应该如何在连接字符串中指定位置元数据?


解决方案

是我以前见过这个问题。而这只是一个时间问题,有人问过这个问题。

基本上 RES:// * / 加载在所有组件的所有元数据,所以如果有一个以上的元数据集EF的迷糊。

因此​​,使用 RES:// * / 默认为EF确实在web应用中的一个bug,遗憾的是它是一个我们没有时间来解决<。 / p>

解决方法是让更多的具体的连接字符串是这样的:
    RES://*/App_$c$c.Northwind.csdl |高分辨率://*/App_$c$c.Northwind.ssdl |高分辨率://*/App_$c$c.Northwind.msl;

在哪里APP_ code是APP_ code文件夹(假设是你的模型在Web项目)和罗斯文是你的EDMX的名称。如果你有麻烦的名字中使用,使用类似反射看看你组装的资源名称。

这样做告诉EF恰好CSDL,SSDL和MSL从加载的程序集加载的,应该解决您的问题。

希望这有助于

亚历

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天全站免登陆