Self referencing loop detected with type

时间:2021-07-16 21:04:24

json.net

namespace EFDAL
{
    using System;
    using System.Collections.Generic;
    using Newtonsoft.Json;
    public partial class MaterielProcedures
    {
        public int Kid { get; set; }
        public Nullable<int> OKid { get; set; }
        public int Node { get; set; }
        public string ProcedureType { get; set; }
        public string ProcedureNeed { get; set; }
        public string Author { get; set; }
        public System.DateTime CreateTime { get; set; }
        public Nullable<System.DateTime> StartTime { get; set; }
        public Nullable<double> PlanHour { get; set; }
        public Nullable<System.DateTime> EndTime { get; set; }
        public Nullable<int> PercentAge { get; set; }
        public string ProcedureState { get; set; }
        public bool IsOut { get; set; }
       
        public  virtual bom_2d  bom_2d { get; set; }
    }
}

var   MPtest = conn.MaterielProcedures.Where(X => X.OKid == Kid).ToList();

string str2 = JsonConvert.SerializeObject(MPtest);  // 报错位置
               Response.Write(str2);

Self referencing loop detected with type
'System.Data.Entity.DynamicProxies.MaterielProcedures_203DBD2B01DBAD67AF86F4C0C0B7C95197B2BF101DB5CE3063BF24A1DEB2DD69'.
Path 'bom_2d.MaterielProcedures'.

外键  哦 ,

官方解说

http://msdn.microsoft.com/zh-tw/library/cd43263e-441d-4b51-a9d0-440090c2f707

个人解决方案

        [JsonIgnore]
        public  virtual bom_2d  bom_2d { get; set; }