首页 > Windows开发 > 详细

C# 递归模型定义。赋值

时间:2018-09-24 22:04:06      阅读:262      评论:0      收藏:0      [点我收藏+]

https://blog.csdn.net/wumiju/article/details/80429412

 public partial class ProductTypeModel:DbEntityModels.ProductType
    {
        public List<ProductTypeModel> SubProductTypeInfo { get; set; }

        
    }

  public IActionResult ListProductType()
        {
            List<Models.ProductTypeModel> listType = new List<Models.ProductTypeModel>();
          var  info = typeBll.Query(x => x.IsDelete == false && x.Fid == 0 && x.Depth == 0);
            foreach (var item in info)
            {
                listType.Add(new Models.ProductTypeModel()
                {
                    ID = item.ID,
                    IsDelete = item.IsDelete,
                    Depth = item.Depth,
                    CreateDate = item.CreateDate,
                    Fid = item.Fid,
                    Remark = item.Remark,
                    Sort = item.Sort,
                    TypeName = item.TypeName,
                    SubProductTypeInfo= subListProductType(item.ID)
                });
            }
            return Json(new { data = listType });
        }

        public List<Models.ProductTypeModel> subListProductType(long fid)
        {
            var dbProductTypeInfo = typeBll.Query(x => x.IsDelete == false && x.Fid == fid);
            List<Models.ProductTypeModel> listType = new List<Models.ProductTypeModel>();
            foreach (var item in dbProductTypeInfo)
            {
                listType.Add(new Models.ProductTypeModel()
                {
                    ID = item.ID,
                    IsDelete = item.IsDelete,
                    Depth = item.Depth,
                    CreateDate = item.CreateDate,
                    Fid = item.Fid,
                    Remark = item.Remark,
                    Sort = item.Sort,
                    TypeName = item.TypeName,
                    SubProductTypeInfo = subListProductType(item.ID)
                });
            }
            return listType;


        }

C# 递归模型定义。赋值

原文:https://www.cnblogs.com/LuoEast/p/9696879.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!