相关疑难解决方法(0)

实体框架MappingException:类型'XXX已被多次映射

我在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的

我完全糊涂了,我不知道是什么导致了这个问题.

有谁能够帮我?

.net c# entity-framework

26
推荐指数
2
解决办法
9660
查看次数

标签 统计

.net ×1

c# ×1

entity-framework ×1