我是C#和dotnet core的新手。我从数据库获取数据,如下所示。这些数据非常平面化。我需要将其转换为另一个对象。
public class Lead
{
public long Id { get; set; }
public short LeadCreatorId { get; set; }
public short LeadOwnerId { get; set; }
public string ProductId { get; set; }
public LeadPriority Priority { get; set; }
public LeadStatus Status { get; set; }
public long LeadCustomerId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
public string MobileNo { get; set; }
public DateTime CreatedOn { get; set; }
}
我需要将其转换为以下对象。
public class LeadDto
{
public long Id { get; set; }
public short LeadCreatorId { get; set; }
public short LeadOwnerId { get; set; }
public string ProductId { get; set; }
public LeadPriority Priority { get; set; }
public LeadStatus Status { get; set; }
public LeadCustomer LeadCustomer { get; set; }
public DateTime CreatedOn { get; set; }
}
LeadCustomer 如下所示 -
public class LeadCustomer{
public long Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
public string MobileNo { get; set; }
}
我该如何轻松地完成这个任务呢?我可以使用DTO进行转换吗?