Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoMapper .ForMember method compilation error. Invalid overload

I am trying to map using Automapper

Here is my current mapping:

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))

So from a NameAddress source object, I want to map to the PersonalDetails destination object. The rest of the properties on both source and destination are the same, so not explicitly defined the mappings.

However when I try to compile using this mapping I get the following compile time error.

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.

What am I missing? Is my mapping incorrect? It appears to be attempting to user an overload of the function that I don't intend to use.

like image 772
Brett Avatar asked Feb 15 '13 14:02

Brett


1 Answers

My mistake...

Should have been using:

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))
like image 122
Brett Avatar answered Nov 19 '22 19:11

Brett