我在Web应用程序中使用Entity框架.每个请求创建ObjectContext(使用HttpContext),特此代码:
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;
Run Code Online (Sandbox Code Playgroud)
不是每次都有,但有时我有这个例外:
用户代码未处理System.Data.MappingException消息=类型"XXX"已被多次映射.来源= System.Data.Entity的
我完全糊涂了,我不知道是什么导致了这个问题.
有谁能够帮我?