Abp 级联查询序列化时循环引用报错

    [Table("School")]
    public class School : Entity<int>
    {

        public string Name { get; set; }

        public virtual List<Student> Students { get; set; } 
    }

    [Table("Student")]
    public class Student : Entity<int>
    {
        [Required]
        public virtual School School { get; set; }

        public string Name { get; set; }
    }

实体是这样,序列化时,School中有Students,Student中有School,序列化时会造成循环引用的错误。

解决方法:

 

 在Host项目的Startup.cs的ConfigureServices方法中,添加上图红框中的代码,设置循环引用不序列化。

options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;

 

posted @ 2020-07-08 15:23  liuyong111  阅读(453)  评论(0编辑  收藏  举报