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] 特性即可解决
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步