c# - 将实体映射到模型
问题描述
我有一个带有字符串 _description 和 List 注释的结构。我怎样才能将它们都映射,以便它可能发生这样的事情?
public IObjective MapEntityToModel(IObjectiveEntity objectiveEntity)
{
return new Objective
(
objectiveEntity._Id,
objectiveEntity.Name,
objectiveEntity.Description,
objectiveEntity.Comments,
(PriorityType)Enum.Parse(typeof(PriorityType), objectiveEntity.PriorityType)
);
}
如您所见,Description 和 Comments 下面是结构的两种类型,其中 Comments 是字符串列表。错误消息显示我没有接受 5 个参数的构造函数,这当然是因为我在 Obective 类的构造函数中定义了一个结构而不是字符串和字符串列表。我应该如何进行?
解决方案
public IObjective MapEntityToModel(IObjectiveEntity objectiveEntity)
{
return new Objective
(
objectiveEntity._Id,
objectiveEntity.Name,
new TaskDetails
(
objectiveEntity.Description,
objectiveEntity.Comments
),
(PriorityType)Enum.Parse(typeof(PriorityType), objectiveEntity.PriorityType)
);
}
谢谢你们!我需要调用新的 TaskDetails,这就是它的修复方法!:) 这就是从数据库中移出时的工作原理!
推荐阅读
- python-3.x - 如何在 Google Colab 中使用 GUI?
- php - 如何从 API 资源中获取 Json 数组并在 laravel 中使用 Jquery ajax 将其绑定到刀片文件中?
- python-3.x - 如何在请求期货中使用“继续”?
- c - 浮点数中的相关幂
- c# - 托管 Blazor 的 ConfigureServices 中的空 WebRootPath
- python - Django [Errno13] 尝试上传到静态文件夹时出现 PermissionError
- javascript - Javascript中的三重引号
- python - 在tex中写方程时使用变量。循环变量以编写不同的方程
- angular - 如何调试 RxJS / Angular?发出新值时视图不更新
- multithreading - 如何通过负载均衡进行对称矩阵的计算?