0

我有以下课程

资源:

public class NewBusinessSubmission
{
    //other properties      
    public int? TermTypeId { get; set; }

}

目的地:

NewBusinessSubmission 类继承自如下所示的 PolicyTransaction 类(是的,它是 VB.NET):

<System.Serializable()> Public MustInherit Class PolicyTransaction
    Inherits Framework2.BusinessBase(Of PolicyTransaction)
    Implements IDisposable

  ...........

Public Property TermTypeId() As Nullable(Of Integer)
    Get
        CanReadProperty(True)
        If Not _PolicyTermsDataRow.IsTermTypeIdNull Then
            Return Me._PolicyTermsDataRow.TermTypeId
        End If
    End Get
    Set(ByVal value As Nullable(Of Integer))
        If Nullable(Of Integer).Equals(value, Me.TermTypeId) Then Exit Property
        CanWriteProperty(True)
        If value.HasValue Then
            Me._PolicyTermsDataRow.TermTypeId = value.Value
        Else
            Me._PolicyTermsDataRow.SetTermTypeIdNull()
        End If
        AfterTermTypeIdChanged()
        Me.PropertyHasChanged()
    End Set
End Property
  ...........


End Class

下面的映射配置没有设置 TermTypeId:

    Mapper.CreateMap<NewBusinessSubmission, NewBusiness>()
        .ForMember(x => x.PolicyTxnNum, opt => opt.Ignore())
        .ForMember(x => x.ContactProducerLicId, opt => opt.Ignore())
        .ForMember(x => x.PolicyNames, opt => opt.Ignore())
        .ForMember(x => x.PolicyExp, opt => opt.Ignore());

这个也不起作用:

    Mapper.CreateMap<NewBusinessSubmission, NewBusiness>()
        .ForMember(x => x.PolicyTxnNum, opt => opt.Ignore())
        .ForMember(x => x.ContactProducerLicId, opt => opt.Ignore())
        .ForMember(x => x.PolicyNames, opt => opt.Ignore())
        .ForMember(x => x.PolicyExp, opt => opt.Ignore())
        .ForMember(x => x.TermTypeId, opt => opt.MapFrom(x => x.TermTypeId));

我这样称呼地图:

        var newBusiness = Mapper.Map<NewBusinessSubmission, NewBusiness>(newBusinessSubmission);

在 Set() 方法中具有相似代码的所有其他属性都正确映射,我也可以像这样手动映射 TermTypeId:

        newBusinessInstance.TermTypeId = newBusinessSubmissionInstance.TermTypeId;

关于为什么此属性未正确映射的任何想法?

谢谢。

4

0 回答 0