zoukankan      html  css  js  c++  java
  • 序列化类型为.......的对象时检测到循环引用。

    一、今天在项目中,发现如果设置了外键,并且有对应的外键值,那么在在项目中引用的时候会报错以下信息:
    序列化类型为“System.Data.Entity.DynamicProxies.R_UserInfo_ActionInf_E6FE460454B8AEC9462F77C99957ED78980DD5541E378C93E9070840D5499446”的对象时检测到循环引用。 
    解决方案:
    在EF上下文中加入: dbcontext.Configuration.ProxyCreationEnabled = false;
    以下是没有加的EF操作类。

    加了之后如下:

    using Model;
    using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Linq;
    using System.Runtime.Remoting.Messaging;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace DAL
    {
        public class DbContextFactory
        {
            public static DbContext CreateDbContext()
            {
                DbContext dbcontext = (DbContext)CallContext.GetData("dbcontext");
                if (dbcontext == null)
                {
                    dbcontext = new OAEntities1();
                    CallContext.SetData("dbcontext", dbcontext);  //key ,values,并且将new的值放在callcontext线程中
                    dbcontext.Configuration.ProxyCreationEnabled = false;     //处理循环使用报错异常
                }
                return dbcontext;
                //下一步,在dbsession和baseDal中调用上面的方法,完成EF实例的创建
            }
        }
    }
  • 相关阅读:
    矩阵快速幂
    快速排序
    用闭包来实现命令模式
    闭包和面向对象设计
    闭包及其作用
    阿里笔试
    如何在节点上添加样式
    getComputedStyle与currentStyle获取样式(style/class)
    今日头条笔试
    牛客网JavaScript编程规范
  • 原文地址:https://www.cnblogs.com/wangjinya/p/10882635.html
Copyright © 2011-2022 走看看