使用AutoMapper将对象展平为int

Moo*_*Moo 4 asp.net-mvc automapper

我在AutoMapper中有以下Map:

AutoMapper.Mapper.CreateMap<MySourceObject, Int32>()
    .ForMember(d => d, o => o.MapFrom(s => s.Id));
Run Code Online (Sandbox Code Playgroud)

我试图Id将源对象的属性映射到仅int作为目标.

不幸的是,上面给出了以下错误:

Custom configuration for members is only supported for
              top-level individual members on a type
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

我想要实现的是不需要将整个复杂对象传递给ViewModel,当我需要的是Id绑定到a时DropDownList,因为返回的POSTed表单不会重新创建复杂对象,只需返回int.一个int是我需要的:)

现在,我可以在代码中自己完成这项工作,但这样就减少了使用automapper的重点.

arc*_*hil 11

Mapper.CreateMap<MySourceObject, int>().ConstructUsing(source => source.Id);
Run Code Online (Sandbox Code Playgroud)