Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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?

like image 437
David Hammond Avatar asked Jan 29 '10 21:01

David Hammond


People also ask

How do I change the connection string in EDMX?

If you want to change the connection string go to the app. config and remove all the connection strings. Now go to the edmx, right click on the designer surface, select Update model from database, choose the connection string from the dropdown, Click next, Add or Refresh (select what you want) and finish.

What is metadata in connection string?

The Metadata parameter contains a list of locations for the EntityClient provider to search for model and mapping files. Model and mapping files are often deployed in the same directory as the application executable file.


1 Answers

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

like image 200
Alex James Avatar answered Sep 17 '22 13:09

Alex James