Home > C#, Entity Framework > Entity Framework 4–Load metadata exception

Entity Framework 4–Load metadata exception

What could be more simple?

I’ve created Console project (same for Test projects) to check my DAL created with EntityFramework 4. Everything looked Located right, everything compile, and yet, I keep get the following message:

“The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.”

So I open Google to find out what it is. I found some great posts, talk about a case like mine – when the edmx model is not the executed one. Some said copy the config file, some said edit the connection string and tell to EF where to find the Meatadata,
But somehow – still nothing worked for me.

After a short investigation, I discovered that when the model is called the first time, all the metadata uploaded to memory, according to the metadata section in the connection string:

provider connection string="
data source=.\sql2008;
initial catalog=AdventureWorks;
integrated security=True;

My solution actually contains three projects: one containing the model, second containing the Entities created by using the SelfTracking template, and the third – the console project I ran.
In fact, only because I called only classes from the second and third projects –the DLL that contains the metadata files as a resource not yet been loaded to memory, so the metadata didn’t found.
When ObjectContext constructor called, he actually scans all loaded files for metadata resource, and if he cant find it, he throws the exception above.

All you need do is force the loading of the metadata DLL, like calling Assembly.LoadFile () or something similar, or by simply declare a class from that DLL, and it will load automatically.

Categories: C#, Entity Framework Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: