Entity framework MappingException: The type 'XXX has been mapped more than once

Posted by Michal on Stack Overflow See other posts from Stack Overflow or by Michal
Published on 2010-06-17T11:44:10Z Indexed on 2010/06/17 12:03 UTC
Read the original article Hit count: 986

Filed under:
|
|

Hi everyone, I'm using Entity framework in web application. ObjectContext is created per request (using HttpContext), hereby code:

string ocKey = "ocm_" + HttpContext.Current.GetHashCode().ToString();
if (!HttpContext.Current.Items.Contains(ocKey))
{
    HttpContext.Current.Items.Add(ocKey, new ElevationEntityModel(EFConnectionString));
}
_eem = HttpContext.Current.Items[ocKey] as ElevationEntityModel;

Not every time, but sometimes I have this exception:

System.Data.MappingException was unhandled by user code Message=The type 'XXX' has been mapped more than once. Source=System.Data.Entity

I'm absolutely confused and I don't have any idea what can caused this problem.

Can anybody help me?

Thanks.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET