I'm trying to map from one object to another that has a public readonly Guid Id, which I want to ignore. I have tried like this:
Mapper.CreateMap<SearchQuery, GetPersonsQuery>()
.ForMember(dto => dto.Id, opt => opt.Ignore());
This seems to fail because Id is readonly:
AutoMapperTests.IsValidConfiguration threw exception:
System.ArgumentException: Expression must be writeable
Is there any way around this?
I don't think ReadOnly fields are supported by AutoMapper. Only way I could get it to work was to wrap the readonly field with a property with only a getter: