C# 递归模型定义。赋值
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# 递归模型定义。赋值的更多相关文章
- [MVC]自定义模型绑定器,从表单对模型进行赋值
一.奇葩的问题 之前自己造轮子的时候,遇到一个很奇怪的问题,虽然需求很奇葩,但是还是尝试解决了一下 当提交的表单里包含多个重复名称的字段的时候,例如 <form action="/Te ...
- Entity Framework 6 Recipes 2nd Edition(11-1)译 -> 从“模型定义”函数返回一个标量值
第11章函数 函数提供了一个有力代码复用机制, 并且让你的代码保持简洁和易懂. 它们同样也是EF运行时能利用的数据库层代码.函数有几类: Rowset Functions, 聚合函数, Ranking ...
- Entity Framework 6 Recipes 2nd Edition(11-2)译 -> 用”模型定义”函数过滤实体集
11-2. 用”模型定义”函数过滤实体集 问题 想要创建一个”模型定义”函数来过滤一个实体集 解决方案 假设我们已有一个客户(Customer)和票据Invoice)模型,如Figure 11-2所示 ...
- Entity Framework 6 Recipes 2nd Edition(11-2)译 -> 为一个”模型定义”函数返回一个计算列
11-3. 为一个”模型定义”函数返回一个计算列 问题 想从”模型定义”函数里返回一个计算列 解决方案 假设我们有一个员工(Employee)实体,属性有: FirstName, LastName,和 ...
- Entity Framework 6 Recipes 2nd Edition(11-4)译 -> 在”模型定义”函数里调用另一个”模型定义”函数
11-4.在”模型定义”函数里调用另一个”模型定义”函数 问题 想要用一个”模型定义”函数去实现另一个”模型定义”函数 解决方案 假设我们已有一个公司合伙人关系连同它们的结构模型,如Figure 11 ...
- Entity Framework 6 Recipes 2nd Edition(11-5)译 -> 从”模型定义”函数返回一个匿名类型
11-5. 从”模型定义”函数返回一个匿名类型 问题 想创建一个返回一个匿名类型的”模型定义”函数 解决方案 假设已有游客(Visitor) 预订(reservation)房间(hotel ) 的模型 ...
- Entity Framework 6 Recipes 2nd Edition(11-6)译 -> 从一个”模型定义”函数里返回一个复杂类型
11-6.从一个”模型定义”函数里返回一个复杂类型 问题 想要从一个”模型定义”函数返回一个复杂类型 解决方案 假设我们有一个病人(patient)和他们访客(visit)的模型,如 Figure 1 ...
- python基础学习1-变量定义赋值,屏幕输入输出
一.变量定义赋值 输入输出屏幕显示 : name = input("input is your name") age =int( input("input is your ...
- beego——模型定义
复杂的模型定义不是必须的,此功能用作数据库数据转换和自动建表 默认的表名规则,使用驼峰转蛇形: AuthUser -> auth_user Auth_User -> auth__user ...
随机推荐
- WebAppInitializer类,代替web.xml
package com.ssm.yjblogs.config; import javax.servlet.MultipartConfigElement; import javax.servlet.Se ...
- hive 将一个分区表数据全部插入另外一个分区表
假如现在hive有个分区表A,分区字段为dt 需求是:需要将A表中的数据全部插入到分区表B中 具体步骤如下: 1.create B like A: 2.插入数据 set hive.exec.dynam ...
- nginx tomcat https
.首先确保机器上安装了openssl和openssl-devel #yum install openssl #yum install openssl-devel . server { listen s ...
- Caterpillar sis service information training and software
Cat et sis caterpillar heavy duty truck diagnostics repair. Training demonstration allows.cat electr ...
- Python3自定义日志类 mylog
#encoding=utf-8 import os, sysimport datetimeimport time class Mylog(object): # 根文件夹 root_dir = s ...
- camera按键采集图像及waitKey的用法(转)
源: camera按键采集图像及waitKey的用法
- django表单的api
django表单的api,参考文档:https://yiyibooks.cn/xx/Django_1.11.6/ref/forms/api.html 绑定与未绑定形式: Form要么是绑定的,要么是未 ...
- MySQL修改库名的方法
先创建新的库,再用RENAME TABLE 语句移动旧库中的表到新库,最后删除旧库. (root@localhost) [(none)] create database mydb_2; Query O ...
- c++ STL中的next_permutation
default (1) template <class BidirectionalIterator> bool next_permutation (BidirectionalIterato ...
- 微信企业号OAuth2.0验证接口来获取成员的身份信息
<?php $appid = "请输入您企业的appid"; $secret = "请输入您企业的secreat"; if (!isset($_GET[' ...