I have these 2 classes:
public class MyModel()
{
public int Id {get; set;}
public string Name {get; set;}
public bool IgnoreModel {get; set;}
}
public class MyDto()
{
public int Id {get; set;}
public string Name {get; set;}
public bool IgnoreDto {get; set;}
}
I want to ignore both IgnoreModel
and IgnoreDto
. My mapping looks like this:
Mapper.CreateMap<MyModel, MyDto>().Bidirectional()
.ForMember(model=> model.IgnoreModel, option => option.Ignore())
.ForSourceMember(dto => dto.IgnoreDto, option => option.Ignore());
Where Bidirectional() is an extension:
public static IMappingExpression<TDestination, TSource> Bidirectional<TSource, TDestination>(this IMappingExpression<TSource, TDestination> expression)
{
return Mapper.CreateMap<TDestination, TSource>();
}
However, I get an error that IgnoreDto
is not mapped:
`Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type
MyModel -> MyDto (Destination member list) ModelAssembly.MyModel -> DtoAssembly.MyDto (Destination member list)
Unmapped properties: IgnoreDto`
What is the correct way to ignore this kind of mapping?
Mapper.AssertConfigurationIsValid()
? Also, out of curiousity, does droppingBidirectional()
and manually mapping model->dto and dto-> model make any difference? – Nate BarbettiniBidirectional
method come from? – Andrew Whitaker