Newtonsoft环境:LINQ+Newtonsoft
问题:若两表间有外键,如图
如果代码按如下写法则会报错:【Self referencing loop detected with type】
var result = db.T_ZiGeJingLi.Where(p => p.ID == Convert.ToInt32(ZGZSID)); string json = JsonConvert.SerializeObject(result);
经如下修改语句则会正常:
var result = from i in db.T_ZiGeJingLi where i.ID == Convert.ToInt32(ZGZSID) select new { ID = i.ID, ZhengShuBianHao = i.ZhengShuBianHao, ZhengShuMingCheng = i.ZhengShuMingCheng, HuoZhengDate = i.HuoZhengDate, FaZhengJiGou = i.FaZhengJiGou, Memo = i.Memo, EmpID = i.EmpID }; string json = JsonConvert.SerializeObject(result);
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-01 05:27:59