Use AutoMapper to flatten object to int

asp.net-mvc, automapper

Solution

Mapper.CreateMap<MySourceObject, int>().ConstructUsing(source => source.Id);

Problem

I have the following Map in AutoMapper: ``` AutoMapper.Mapper.CreateMap<MySourceObject, Int32>() .ForMember(d => d, o => o.MapFrom(s => s.Id)); ``` I am trying to map the `Id` property of the source object to just an `int` as the destination. Unfortunately, the above gives the following error: ``` Custom configuration for members is only supported for top-level individual members on a type ``` Any ideas? What I am trying to achieve is not having to pass an entire complex object through to the ViewModel when all I need is the `Id` to bind to a `DropDownList`, as the returning POSTed form won't recreate the complex object, just return the int. An `int` is all I need :) Now, I could do this myself in code, but then that diminishes the point of having automapper.

Original source