RSS

Object mapping could not be found for Type with identity {X}

02 May

If you try executing TryGetObjectByKey and you get the error above, you have missed to set the MetadataWorkspace in your ObjectContext.
This is achieved by doing the following:

Assembly a = typeof(MyContext).Assembly;
//ctx is the ObjectContext
ctx.MetadataWorkspace.LoadFromAssmebly(a);

After that you will be able to execute TryGetObjectByKey or other methods without getting exceptions.

Advertisements
 
Leave a comment

Posted by on May 2, 2012 in C-Sharp, EF

 

Tags:

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

 
%d bloggers like this: