When utilizing EF4's POCO Template, you get the message "Metadata information not found."

efpocoadapter entity-framework poco


I recently set up the EF4 POCO Template. My model just has the single entity AnnouncementText, and the T4 files seem to have been created correctly. When I try to access this new object, the auto-generated property throws the following error.MyObjectContext.AnnouncementTexts :

InvalidOperationException: Mapping and metadata information could not be found for EntityType 'MyNamespace.AnnouncementText'.

The residences on theAnnouncementText I haven't altered any of the auto-generated code, and POCO seem to correspond with the database values.

This is the stack trace:

   at System.Data.Objects.ObjectContext.GetTypeUsage(Type entityCLRType)
   at System.Data.Objects.ObjectContext.GetEntitySetForNameAndType(String entitySetName, Type entityCLRType, String exceptionParameterName)
   at System.Data.Objects.ObjectContext.CreateObjectSet[TEntity](String entitySetName)
   at MyNamespace.MyObjectContext.get_AnnouncementTexts() in C:\<snip>\MyObjectContext.Context.cs:line 65
   at MyNamespace.Class1.Main() in C:\<snip>\Class1.cs:line 14

Delete the if.tt I can access the property without any problems if I remove the solution's files and allow code generation on the model.

If it's any help, this is my code:

using (var context = new MyObjectContext())
   foreach (var at in context.AnnouncementTexts)

Any suggestions as to what could be wrong?

2/11/2010 9:35:32 PM

Accepted Answer

I just encountered this problem once again when relocating my EDMX file inside the solution. It seems that while working with EDMX files, there are a few distinct namespaces. There are two namespaces: one that shows in the SSDL and looks somewhat like this (N2), and one that you input using the wizard when you create the first EDMX file.

<Schema Namespace="..." ..

Finally, there are the hidden namespaces of the resources that are compiled into your final assembly. The namespace of the produced code may (optionally) be set in the designer (N3) (N4).

Namespace N2, as far as I can determine, only truly matters inside the SSDL. I think the namespace is first entered as N1 when using the wizard.

Similar to how C# namespaces often are, namespace N3 is exclusively relevant in that sense.

Here's when things become tricky. The directory where your EDMX is located namespaces serve as category namespaces (relative to your project directory). You may be asking, "So what?" It turns out that your App.config file also makes reference to those namespaces. Look for a component like this one in particular:


Your CSDL resource is identified by the text "Database.Master.csdl" in that section. You'll see an error similar to the one shown above if those resource names diverge, or perhaps:

The specified default EntityContainer name '[name]' could not be found in the mapping and metadata information.

Changing your App.config to indicate the appropriate resource name for each component of your EF mapping is the straightforward fix (CSDL, SSDL, and MSL). Check out your built assembly's resources in ILSpy or dotPeek if you're unsure of the names precisely.

2/18/2012 7:04:56 PM

Popular Answer

The Build Action (in the Properties pane) in the destination project will return to the default value of "None" if you transplant an EDMX file to another project. This may result in the "EntityContainer name... could not be found" issue since no resources are being produced. (If this is the case, there won't be any resources when you open the DLL containing the model in Reflector.) This may be fixed by recreating the solution and setting the Build Action to "EntityDeploy".

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow