c# - 属性的动态映射
问题描述
如果有任何方法可以将子对象属性动态映射或添加到父对象,我很感兴趣?例如,我有以下课程:
public class Parent {
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Child> Children { get; set; }
}
public class Child {
public int Id { get; set; }
public string Name { get; set; }
}
我需要以以下格式从后端发送到前端:
public class Dto {
public int ParentId { get; set; }
public string ParentName { get; set; }
public string Child1Name { get; set; }
public string Child2Name { get; set; }
public string Child3Name { get; set; }
}
请记住,父对象可以有不同数量的子对象。我需要这种格式的信息,因为它将显示在网格中(见下图)。这样的事情可以实现吗?如何实现?
解决方案
推荐阅读
- java - 没有足够的堆内存来运行 weka 3.8.4
- javascript - 当我尝试在端口 5500 上启动 localhost 时,Google Chrome 无法连接
- ruby-on-rails - Rails 订单搜索结果
- php - 如何在 php 中使用正则表达式检查数组上的 url?
- docker - 每次我想运行时,我的 HAproxy 容器都会退出
- django - 如何在 Django REST API 视图中加载 Keras 模型
- python - 如果值已存在于 mongodb 中,则将其删除,否则将其添加到列表末尾(mongoengine)
- javascript - 更改其他脚本结果的 javascript 变量
- node.js - Node JS 在异步 json 调用中返回 undefined
- android - 在 ExoPlayer 中启用延迟缓冲