ADO.NET entity framework throws the following exception when creating an entity context:
System.ArgumentException: The specified default EntityContainer name [NAME] could not be found in the mapping and metadata information. Parameter name: defaultContainerName
at System.Data.Metadata.Edm.ClrPerspective.SetDefaultContainer(String defaultContainerName)
at System.Data.Objects.ObjectContext.set_DefaultContainerName(String value)
at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName)
This error can mean a mismatch between the metadata referenced in the connection string (i.e., in config) and theembedded resource in your assembly. You have probably noticed that entity framework connection strings contain a much more than typical db connection strings. In fact the db connection is just one of its properties. So what are the other properties?
- metadata: lists the three metadata resources required by entity framework (CSDL, SSDL, MSL). For more info on these see entity framework metadata resources.
- provider: the .Net data provider
- provider connection string: the underlying db connection string (this is the 'typical' ado.net connection string). Note that this string is quoted inside the EF CS using "
Now if the names of any of the resources in the metadata property don't match the resources actually embedded in your assembly, then you'll get this error. How do I tell what the names of the embedded resources are? Open your assembly using .Net Reflector. Look under resources - you should see the three EF metadata resources. Check your connection string and make sure they match.