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# 递归模型定义。赋值的更多相关文章

  1. [MVC]自定义模型绑定器,从表单对模型进行赋值

    一.奇葩的问题 之前自己造轮子的时候,遇到一个很奇怪的问题,虽然需求很奇葩,但是还是尝试解决了一下 当提交的表单里包含多个重复名称的字段的时候,例如 <form action="/Te ...

  2. Entity Framework 6 Recipes 2nd Edition(11-1)译 -> 从“模型定义”函数返回一个标量值

    第11章函数 函数提供了一个有力代码复用机制, 并且让你的代码保持简洁和易懂. 它们同样也是EF运行时能利用的数据库层代码.函数有几类: Rowset Functions, 聚合函数, Ranking ...

  3. Entity Framework 6 Recipes 2nd Edition(11-2)译 -> 用”模型定义”函数过滤实体集

    11-2. 用”模型定义”函数过滤实体集 问题 想要创建一个”模型定义”函数来过滤一个实体集 解决方案 假设我们已有一个客户(Customer)和票据Invoice)模型,如Figure 11-2所示 ...

  4. Entity Framework 6 Recipes 2nd Edition(11-2)译 -> 为一个”模型定义”函数返回一个计算列

    11-3. 为一个”模型定义”函数返回一个计算列 问题 想从”模型定义”函数里返回一个计算列 解决方案 假设我们有一个员工(Employee)实体,属性有: FirstName, LastName,和 ...

  5. Entity Framework 6 Recipes 2nd Edition(11-4)译 -> 在”模型定义”函数里调用另一个”模型定义”函数

    11-4.在”模型定义”函数里调用另一个”模型定义”函数 问题 想要用一个”模型定义”函数去实现另一个”模型定义”函数 解决方案 假设我们已有一个公司合伙人关系连同它们的结构模型,如Figure 11 ...

  6. Entity Framework 6 Recipes 2nd Edition(11-5)译 -> 从”模型定义”函数返回一个匿名类型

    11-5. 从”模型定义”函数返回一个匿名类型 问题 想创建一个返回一个匿名类型的”模型定义”函数 解决方案 假设已有游客(Visitor) 预订(reservation)房间(hotel ) 的模型 ...

  7. Entity Framework 6 Recipes 2nd Edition(11-6)译 -> 从一个”模型定义”函数里返回一个复杂类型

    11-6.从一个”模型定义”函数里返回一个复杂类型 问题 想要从一个”模型定义”函数返回一个复杂类型 解决方案 假设我们有一个病人(patient)和他们访客(visit)的模型,如 Figure 1 ...

  8. python基础学习1-变量定义赋值,屏幕输入输出

    一.变量定义赋值 输入输出屏幕显示 : name = input("input is your name") age =int( input("input is your ...

  9. beego——模型定义

    复杂的模型定义不是必须的,此功能用作数据库数据转换和自动建表 默认的表名规则,使用驼峰转蛇形: AuthUser -> auth_user Auth_User -> auth__user ...

随机推荐

  1. 支持向量机SVM 参数选择

    http://ju.outofmemory.cn/entry/119152 http://www.cnblogs.com/zhizhan/p/4412343.html 支持向量机SVM是从线性可分情况 ...

  2. python 试题归纳及答疑 更新中.....

    一.Python基础篇(80题) 1.你为什么学习Python? 一.答题思路 1.阐述 python 优缺点 2.Python应用领域说明 3.根据自身工作情况阐述为什么会使用python 1)py ...

  3. Spark学习之路 (十六)SparkCore的源码解读(二)spark-submit提交脚本

    一.概述 上一篇主要是介绍了spark启动的一些脚本,这篇主要分析一下Spark源码中提交任务脚本的处理逻辑,从spark-submit一步步深入进去看看任务提交的整体流程,首先看一下整体的流程概要图 ...

  4. [转载]FlipClock.js时钟,计数,3D翻转插件

    1.FlipClock.js能够自动定义计数,时钟的翻牌效果,调用简单,下面简单记录下用法 2.官网地址:http://www.flipclockjs.com/ 3.调用2个文件 <link h ...

  5. API gateway 之 kong 安装

    kong安装: https://getkong.org/install/centos/ 下载指定版本rpm: wget https://bintray.com/kong/kong-community- ...

  6. Flask-----轻量级的框架,快速的搭建程序

    Flask是一个基于Python开发并且依赖jinja2模板和Werkzeug WSGI服务的一个微型框架,对于Werkzeug本质是Socket服务端,其用于接收http请求并对请求进行预处理,然后 ...

  7. 自学Java第一周的总结

    在第一周里我花费了不少时间配置jdk的环境变量,并学习了有关java的基本知识,了解了Java中的变量.数据类型以及运算符.我知道了什么是变量并且如何去定义变量,也学会了如何去使用运算符以及对数据类型 ...

  8. C#简单线程

    一.实例1 static void Main(string [] args) { Console.WriteLine("开始线程"); startFunc(); Console.W ...

  9. 模型(model-->orm)系统

    一.ORM介绍 1)ORM概念 对象关系映射(Object Relational Mapping,简称ORM)模式是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术. 简单的说,ORM是通过 ...

  10. django模板常用过滤器—add、cut、date

    语法格式:{{  obj | filter:para  }} add过滤器:将两个数相加或字符串.列表等进行拼接 views.py def add(request): context={'l1':[1 ...