EF 多对多循环引用序列化失败 解决办法

错误:Self referencing loop detected with type 'System.Data.Entity.DynamicProxies.tbldph_901D48A194FB31357

 添加[JsonIgnore] 可解决
 [Table("tbldph")]
    public partial class tbldph
    {
        public tbldph()
        {
            tbldphcaselinks = new HashSet<tbldphcaselink>();
            tbldphnotices = new HashSet<tbldphnotice>();
            tbldphparticipants = new HashSet<tbldphparticipant>();
            tbldphpagelinks = new HashSet<tbldphpagelink>();
        }

        [Key]
        public int DphId { get; set; }

        public int? Series_DphSeriesId { get; set; }

        [ForeignKey("Series_DphSeriesId")]
        public virtual tbldphseries Series { get; set; }

        public long? Mc_UserId { get; set; }

        [ForeignKey("Mc_UserId")]
        public virtual tbluser Mc { get; set; }

        public long? Creator_UserId { get; set; }

        [ForeignKey("Creator_UserId")]
        public virtual tbluser Creator { get; set; }
public DateTime? CreateTime { get; set; }

        public DateTime? LastModifyTime { get; set; }

        public virtual ICollection<tbldphcaselink> tbldphcaselinks { get; set; }

        public virtual ICollection<tbldphnotice> tbldphnotices { get; set; }

        public virtual ICollection<tbldphpagelink> tbldphpagelinks { get; set; }

      
        [InverseProperty("tbldph")]
        public virtual ICollection<tbldphparticipant> tbldphparticipants { get; set; }
      
        [InverseProperty("tbldph")]
        public virtual ICollection<tbldphattachment> tbldphattachments { get; set; }
        public string test { get; set; }
        public string Content { get; set; }
    }

 

 [Table("tbldphcaselink")]
    public partial class tbldphcaselink
    {
        [Key]
        public int DphCaseLinkId { get; set; }

        public int DphId { get; set; }

        public int CaseId { get; set; }

        public int? CheckID { get; set; }


        [JsonIgnore]
        [ForeignKey("DphId")]
        public virtual tbldph tbldph { get; set; }
    }

 

 

解决办法:外键添加[JsonIgnore] 特性即可解决

转载于:https://www.cnblogs.com/xhxsk/p/10572438.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值