views:

481

answers:

1

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?

+1  A: 

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

Alex James
Thank you so much for your reply, Alex. The resource paths you suggest make sense, and I'm amazed that in all my stumbling around this afternoon I didn't try that. It worked, in any case.One more question. If it hadn't worked I wouldn't know where to find the App_Code assembly to look at it with Reflector. Where would that be? This is something else I think I should know, or should be able to find easily online, but my Google foo has been horrible today.
David Hammond
Did you look in your bin directory?
Alex James
I have looked there, but there's nothing there but dlls that have been explicitly added to the project. I must be missing something. Do I need to precompile the site?
David Hammond
We ran into this, too, when we started using precompiled views (even though we have only one assembly with an EF model). And yes, this solution works. Would make a good tip!
Craig Stuntz