我在Web应用程序中使用Entity Framework。 对象上下文是每个请求(使用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;
并非每次都出现,但有时我会遇到这个异常:
System.Data.MappingException未被用户代码处理 Message=类型“XXX”已映射多次。 Source=System.Data.Entity
我很困惑,也不知道是什么引起了这个问题。
有人能帮帮我吗?