In ASP.NET Core-6 Web API Entity Framework, I am mapping DTO to models using AutoMapper. I have two models Customer and CustomerDetail. Customer will have only one CustomerDetail:
I have these Models:
public class Customer
{
    public Guid Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string MobileNumber { get; set; }
    public string Email { get; set; }
    public string MobileNumber { get; set; }
    public string UserType { get; set; } 
    public bool? IsAdmin { get; set; }
    public bool? IsActive { get; set; }
    public virtual CustomerDetail CustomerDetail { get; set; }
}
public class CustomerDetail
{
    public string Id { get; set; }
    public Guid BusinessName { get; set; }
    public string AccountNumber { get; set; }
    public Guid CustomerId { get; set; }
    public CustomerStatus? CustomerStatus { get; set; }
    public Guid? BankId { get; set; }
    public decimal? ChargeValue { get; set; }
    public virtual Customer Customer { get; set; }
    public virtual Bank Bank { get; set; }
}
CreateCustomerDto:
public class CreateCustomerDto
{
    public string BusinessName { get; set; }
    public string AccountNumber { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string MobileNumber { get; set; }
    public string Email { get; set; }
    public string MobileNumber { get; set; }
    public decimal? ChargeValue { get; set; }
}
The Customer and CustomerDetail are inserted into the DB together at the same time. So, I am mapping the two models to a single DTO (CreateCustomerDto).
I want to map only the fields in the CreateCustomerDto into the two models and exclude or ignore the other ones. So far, I have done this:
CreateMap<CreateCustomerDto, Customer>().ReverseMap();
CreateMap<CreateCustomerDto,CustomerDetail>().ReverseMap();
How do I achieve my goal?
Thanks
 
    