AutoMapper/AutoMapper.Extensions.ExpressionMapping

Argument types do not match if int is mapped to Enum

oklipilin opened this issue · 1 comments

Version used is 3.1.1
Here are classes and mappings:

    public enum TestEnum
    {
        Prop0 = 0,
        Prop1 = 1
    }

    public class MyEntity
    {
        public int PropVal { get; set; }
    }

    public class MyModel
    {
        public TestEnum PropVal { get; set; }
    }

    public class TestProfile : Profile
    {
        public TestProfile()
        {
            CreateMap<MyEntity, MyModel>()
                .ForMember(e => e.PropVal, o => o.MapFrom(s => (TestEnum)s.PropVal))
                .ReverseMap()
                .ForMember(e => e.PropVal, o => o.MapFrom(s => (int)s.PropVal));
        }
    }

Here is my code:

    var model = new MyModel
    {
        PropVal = TestEnum.Prop1
    };

    var mappedModel = mapper.Map<MyEntity>(model); // works fine

    Expression<Func<MyModel, MyModel>> expr = m => new MyModel { PropVal = m.PropVal };

    var mappedExpr = mapper.MapExpression<Expression<Func<MyEntity, MyEntity>>>(expr); // -> Argument types do not match

The MyGet build should work now. Thanks.