开发者

How to specify metadata location in connection string when using an edmx file

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 开发者_StackOverflow社区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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜