• 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] 特性即可解决

  • 相关阅读:
    DFS,BFS算法
    浙江理工大学7月月赛
    矩阵快速幂
    数塔
    Bone Collector
    畅通工程
    敌兵布阵
    Tempter of the Bone
    Elevator
    Fibonacci Again
  • 原文地址:https://www.cnblogs.com/xhxsk/p/10572438.html
Copyright © 2020-2023  润新知