I am new in C#, dotnet core. I am getting data from database like below. This data is very flat. I need to convert to another object.
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; }
}
I need to convert it to below object.
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; }
}
Where LeadCustomer is like below -
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; }
}
How can I easily do that? Can I use dto for the conversion.
They are many many mapper libraries out in the internet. To name a few
All of them have their own pros and cons. I would personally feel writing your own mapper methods would be worth it as you will have complete control of what you write.
I agree it could take some time but it doesn't take so long.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With