在mvc中 序列化对象中如果包含导航属性的化在运行程序中会报Self referencing loop detected for property " 这个错误,由于
.对象相互循环序列化中对象取数据出现异常解决方法
在实体类中应用 using Newtonsoft.Json; 在导航属性字段前面加上 [JsonIgnore] 特性 如下:
namespace OAModel
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
public partial class UserInfo
{
public UserInfo()
{
this.R_UserInfo_ActionInfo = new HashSet<R_UserInfo_ActionInfo>();
this.Department = new HashSet<Department>();
this.RoleInfo = new HashSet<RoleInfo>();
}
public int ID { get; set; }
public string UName { get; set; }
public string UPwd { get; set; }
public System.DateTime SubTime { get; set; }
public short DelFlag { get; set; }
public System.DateTime ModifiedOn { get; set; }
public string Remark { get; set; }
public string Sort { get; set; }
[JsonIgnore] //这里的R_UserInfo_ActionInfo 为导航属性,加上这个特性就不报错了,
public virtual ICollection<R_UserInfo_ActionInfo> R_UserInfo_ActionInfo { get; set; }
[JsonIgnore]
public virtual ICollection<Department> Department { get; set; }
[JsonIgnore]
public virtual ICollection<RoleInfo> RoleInfo { get; set; }
}
}