zoukankan      html  css  js  c++  java
  • c# 递归查找父类的子类

    场景

    在做用户反馈的时候,需要查询该用户反馈表中的数据,有父子关系。表字段如下:

    直接上方法

    /// <summary>
    /// 递归查找父类的子类
    /// </summary>
    /// <param name="list">反馈消息列表数据</param>
    /// <param name="UserName">反馈人</param>
     /// <param name="pid">父类ID</param>
    /// <returns>用户的反馈列表数据</returns>
    public List<DAL.Feedback> GetFeedBack(List<DAL.Feedback> list,string UserName,int pid=0) 
    {   List
    <DAL.Feedback> lst = new List<Feedback>();   if (list.Where(t=>t.FeedbackParentID==pid&&t.FInitiator== UserName).Count()>0)   {     foreach (var item in list.Where(t=>t.FeedbackParentID==pid&&t.FInitiator==UserName).ToList())     {       lst.Add(item);       lst.AddRange(GetFeedBack(list, UserName, (int)item.FID));     }   }   return lst; }

    调用方法

    List<DAL.Feedback> list = Entity.Feedback.AsNoTracking().AsQueryable().ToList();
    List<DAL.Feedback> FeedbackList= GetFeedBack(list,"测试");

    效果图

     也是借鉴网友的,地址:https://blog.csdn.net/xinyanan1992/article/details/52414336

  • 相关阅读:
    LeetCode15 3Sum
    LeetCode10 Regular Expression Matching
    LeetCode20 Valid Parentheses
    LeetCode21 Merge Two Sorted Lists
    LeetCode13 Roman to Integer
    LeetCode12 Integer to Roman
    LeetCode11 Container With Most Water
    LeetCode19 Remove Nth Node From End of List
    LeetCode14 Longest Common Prefix
    LeetCode9 Palindrome Number
  • 原文地址:https://www.cnblogs.com/liuping666/p/12095399.html
Copyright © 2011-2022 走看看