C# EF 查询数据循环应用名问题解决

2021-11-19 09:36:12 浏览数 (2)

{tabs-pane label="解决方式一"}

代码语言:javascript复制
解决方式一:    
      var json = new { total = data.Count(), rows = result };
    
    JsonSerializerSettings jsSettings = new JsonSerializerSettings();
    jsSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
      return JsonConvert.SerializeObject(json, jsSettings);    

{/tabs-pane} {tabs-pane label="解决方式二"}

代码语言:javascript复制
 var data = from a in db.Approver
                           where a.ProcessItemId == strId
                           select new ApproverViewModels
                           {
                               Id = a.Id,
                               JobCode = a.JobCode,
                               AreaLeve = a.AreaLeve,
                               Discrible = a.Discrible,
                               Order = a.Order,
                               ProcessItemId = a.ProcessItemId,
                               ExecuteMethod = a.ExecuteMethod,
                           };
    
                var result = data.OrderBy(x => x.Order).Skip(offset).Take(limit).ToList();
    
                var json = new { total = data.Count(), rows = result };
    
    
                return Json(json, JsonRequestBehavior.AllowGet);

{/tabs-pane}

本文共 15 个字数,平均阅读时长 ≈ 1分钟

0 人点赞