AutoMapper .ForMember方法编译错误。无效的重载

时间:2013-02-15 14:24:38

标签: vb.net automapper

我正在尝试使用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.

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

2 个答案:

答案 0 :(得分: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))

答案 1 :(得分:0)

 Mapper.CreateMap(Of Category, DTOCategory)() _
         .ForMember(Function(c) c.ID, Sub(opt) opt.Ignore()) _
         .ForMember(Function(c) c.NAME, Sub(opt) opt.Ignore())