8

我正在尝试使用 Automapper 进行映射

这是我当前的映射:

Mapper.CreateMap(Of NameAddress, PersonalDetails)() _
            .ForMember(Function(dest) dest.Forenames, Function(opt) opt.MapFrom(Function(src) src.Forename)) _
            .ForMember(Function(dest) dest.TelephoneNumber, Function(opt) opt.MapFrom(Function(src) src.TelephoneNo1)) _
            .ForMember(Function(dest) dest.MobileNumber, Function(opt) opt.MapFrom(Function(src) src.MobilePhoneNo)) _
            .ForMember(Function(dest) dest.NationalInsuranceNumber, Function(opt) opt.MapFrom(Function(src) src.NINo)) _
            .ForMember(Function(dest) dest.DateOfBirth, Function(opt) opt.MapFrom(Function(src) src.BirthDate))

因此,我想从 NameAddress 源对象映射到 PersonalDetails 目标对象。源和目标上的其余属性是相同的,因此没有明确定义映射。

但是,当我尝试使用此映射进行编译时,会出现以下编译时错误。

Overload resolution failed because no accessible 'ForMember' can be called with these arguments:
    'Public Function ForMember(name As String, memberOptions As System.Action(Of AutoMapper.IMemberConfigurationExpression(Of Infrastructure.NameAddress))) As AutoMapper.IMappingExpression(Of Infrastructure.NameAddress, Core.TaxiLicensing.PersonalDetails)': Lambda expression cannot be converted to 'String' because 'String' is not a delegate type.
    'Public Function ForMember(name As String, memberOptions As System.Action(Of AutoMapper.IMemberConfigurationExpression(Of Infrastructure.NameAddress))) As AutoMapper.IMappingExpression(Of Infrastructure.NameAddress, Core.TaxiLicensing.PersonalDetails)': Expression does not produce a value.
    'Public Function ForMember(destinationMember As System.Linq.Expressions.Expression(Of System.Func(Of Core.TaxiLicensing.PersonalDetails, Object)), memberOptions As System.Action(Of AutoMapper.IMemberConfigurationExpression(Of Infrastructure.NameAddress))) As AutoMapper.IMappingExpression(Of Infrastructure.NameAddress, Core.TaxiLicensing.PersonalDetails)': Expression does not produce a value.

我错过了什么?我的映射不正确吗?它似乎正在尝试使用我不打算使用的函数的重载。

4

2 回答 2

17

我的错...

应该一直在使用:

Mapper.CreateMap(Of NameAddress, PersonalDetails)() _
            .ForMember(Function(dest) dest.Forenames, Sub(opt) opt.MapFrom(function(src) src.Forename)) _
            .ForMember(Function(dest) dest.TelephoneNumber, sub(opt) opt.MapFrom(function(src) src.TelephoneNo1)) _
            .ForMember(Function(dest) dest.MobileNumber, Sub(opt) opt.MapFrom(function(src) src.MobilePhoneNo)) _
            .ForMember(Function(dest) dest.NationalInsuranceNumber, sub(opt) opt.MapFrom(function(src) src.NINo)) _
            .ForMember(Function(dest) dest.DateOfBirth, Sub(opt) opt.MapFrom(function(src) src.BirthDate))
于 2013-02-15T15:12:18.877 回答
0
 Mapper.CreateMap(Of Category, DTOCategory)() _
         .ForMember(Function(c) c.ID, Sub(opt) opt.Ignore()) _
         .ForMember(Function(c) c.NAME, Sub(opt) opt.Ignore())
于 2016-05-14T20:54:49.593 回答