将实体嵌套到一个 DTO 对象自动映射器中。无法找出正确的映射

Nested entity into one DTO object automapper. Unable to figure out the correct mapping

这是我要转换为 DTO 的主要实体。

我的实体是

public class ServiceBillingInformation
{

    public DateRange EffectiveDate { get; set; }
}

public class DateRange
{
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
}

我的 DTO 是

public class ServiceBillingModel
{
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
}

如何将 DTO 的 StartDateEndDate 分别映射到 EffectiveDate.StartDateEffectiveDate.EndDate

我尝试了很多映射,但我总是在 Mapper.AssertConfigurationIsValid 方法上遇到映射错误。

一种简单的映射方式

Mapper.Initialize( t => 
    t.CreateMap< ServiceBillingInformation, ServiceBillingModel>()
    .ForMember( d => d.StartDate, f =>  f.MapFrom( src => src.EffectiveDate.StartDate ))
    .ForMember( d => d.EndDate, f => f.MapFrom(src => src.EffectiveDate.EndDate))
    );