【发布时间】:2019-07-04 14:19:49
【问题描述】:
我有这两个表“用户”和“项目”。他们共享一对多的关系。 我得到的响应是一个列表,我想将此响应与我创建的 GetProjectManager 的 dto 映射,但我不确定如何在 automapper 配置文件中定义 CreateMap。 我从 ProjectManager 类型的 API 得到了这个响应:
项目经理:
[
{
"id": 1,
"projectId": 1,
"userId": 1,
"project": {
"id": 1,
"projectName": "iDocument-FBAG",
"plannedStartDate": "2019-07-03T00:00:00",
"plannedEndDate": "2019-07-10T00:00:00",
"actualStartDate": null,
"actualEndDate": null,
"projectDescription": "The client wants to enhance their existing .Net application. They have a WebForms application that uses DevExpress controls. They would like to start by implementing a chart type and creating a reusable report, also use that reusable report to implement some new reports.",
"onProjects": [],
"projectManagers": []
},
"user": {
"firstName": "Abc",
"lastName": "Efg",
"isProjectManager": true,
"registrationTime": "2019-06-28T19:28:55.8386138",
"employees": null,
"id": 1,
"userName": "xyz@abc.com"
}
},
{
"id": 3,
"projectId": 8,
"userId": 1,
"project": {
"id": 8,
"projectName": "Aquatrols-FBAG",
"plannedStartDate": "2019-07-03T00:00:00",
"plannedEndDate": "2019-07-10T00:00:00",
"actualStartDate": null,
"actualEndDate": null,
"projectDescription": "The client wants to enhance their existing .Net application. They have a WebForms application that uses DevExpress controls. They would like to start by implementing a chart type and creating a reusable report, also use that reusable report to implement some new reports.",
"onProjects": [],
"projectManagers": []
},
"user": {
"firstName": "Abc",
"lastName": "Efg",
"isProjectManager": true,
"registrationTime": "2019-06-28T19:28:55.8386138",
"employees": null,
"id": 1,
"userName": "xyz@abc.com"
}
}
]
我想将此响应与我创建的 Dto (GetProjectManager) 进行映射。
public class GetProjectManager
{
public string ProjectManagerId { get; set; }
public string Email { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public IList<GetProjectDto> GetProjects { get; set; }
}
public class GetProjectDto
{
public int ProjectId { get; set; }
public string ProjectName { get; set; }
public DateTime PlannedStartDate { get; set; }
public DateTime PlannedEndDate { get; set; }
public DateTime? ActualStartDate { get; set; }
public DateTime? ActualEndDate { get; set; }
public string ProjectDescription { get; set; }
}
public class ProjectManager
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Required]
public int Id { get; set; }
[Required]
public int ProjectId { get; set; }
[Required]
public int UserId { get; set; }
public Project Project { get; set; }
public AppUsers User { get; set; }
}
【问题讨论】:
标签: c# .net-core automapper