views:

2388

answers:

3

Hi, I have encountered an exception when I using Entity Framework 4.0 RC. My Entity Framework model is encapsulated in a private assembly whos name is Procurement.EFDataProvider and my POCO are inside of another assembly Procurement.Core The relation between Core(Business Logic)and EFDataProvider(Data Access) is with a factory named DataProvider

so when I try to create an objectset

objectSet = ObjectContext.CreateObjectSet<TEntity>();

I got an error:

Mapping and metadata information could not be found for EntityType 'Procurement.Core.Entities.OrganizationChart'.

+2  A: 

This is probably because EF can't find the embedded mapping information. Inside your connection string you'll probably have something like his:

metadata=res://*/Models.MyModels.csdl|...etc

That * is a wildcard, telling the object context to try and find the embedded mapping information from, I think, scanning all the loaded assemblies. If the assembly isn't loaded, EF won't find it.

What you need to do is provide the connection string with more information about where your mapping information is embedded. Change the * to the specific assembly name of your mapping code:

metadata=res://Procurement.EFDataProvider/Models.MyModels.csdl

If that fails, find the Assembly and directly load it into your ObjectContext using:

ObjectContext.Metadataworkspace.LoadFromAssembly();
jfar
A: 

Just check the property spelling with the model

soumitra ghosh
+7  A: 

For anyone else dealing with the error, I think it's worth mentioning some scenarios that I've found that cause this (extremely unhelpful) error:

  • Misspelled properties (case-sensitive!)
  • Properties missing in the POCO class
  • Type mismatches between the POCO and entity-type (e.g., int instead of long)
  • Enums in the POCO (EF doesn't support enums right now as I understand)

There might be other causes as well.

HTH

joniba

related questions