Reputation: 5362
I'm using the AutoMapper object mapper, but am getting the exception "Custom configuration for members is only supported for top-level individual members on a type."
Basically I have
public class Obj1
{
public int Id {get;set;}
}
and
public class Obj2
{
public int[] Ids { get; set; }
}
Th exception occurs when I try to create the mapping like;
Mapper
.CreateMap<Obj1, Obj2>()
.ForMember(d => d.Ids[0], o => o.MapFrom(s => s.Id)
);
Why is this happening ? What I'm wanting to achieve is when the objects are mapping that the single int Id in the source is mapped to the first element in the destination int array e.g [0]. The complete exception is
type="AutoMapper.AutoMapperConfigurationException" message="Custom configuration for members is only supported for top-level individual members on a type." source="AutoMapper"
detail="AutoMapper.AutoMapperConfigurationException: Custom configuration for members is only supported for top-level individual members on a type. at AutoMapper.Impl.ReflectionHelper.FindProperty(LambdaExpression lambdaExpression) at AutoMapper.MappingExpression2.ForMember(Expression
1 destinationMember, Action`1 memberOptions) at ...
Upvotes: 1
Views: 2414
Reputation: 1753
You are close - just need to make the array instead of setting a individual member
Mapper.CreateMap<Obj1, Obj2>().ForMember(d => d.Ids, o => o.MapFrom(s => new[]{s.Id}));
Upvotes: 6