3
I’m using Automapper version 7. I need to ignore a property that is in the result class and has no source class. As below.
public class Contrato
{
public string Id{get;set;}
public string Nome {get;set;}
}
public class ContratoDto
{
public string Id{get;set;}
public string Nome {get;set;}
public string Descricao{get;set;}
}
If I use Mapper as below, it gives me the error that has Uncharted Property.
CreateMap<Contrato, ContratoDto>();
var c = _contratoRepositorio.BuscarContrato(requisicao.CodigoContrato).FirstOrDefault();
Mapper.Map<Contrato, ContratoDto>(c));
Unmapped Property: Description
How can I ignore the property in Dto that does not exist and will not exist within the model?
o . Formember(p => p.Property, x=> x.Ignore()) does not work for me. I opened this question precisely because I stress using . Formember and it does not work.
– Thiago Henrique
Tried with the
ForSourceMember
?– Barbetta
@Can Thiagohenrique explain what didn’t work? I think that in version 7 onwards is not used
.Ignore()
, but yes.DoNotValidate()
, make a test and I can put in more detail– Ricardo Pontual
@Barbetta tried them both. neither worked.
– Thiago Henrique
I found the "temporary" solution that for now helped me, but I do not know if it is the correct option.
cfg.ValidateInlineMaps = false;
in Mapper’s Initialize. In this case it failed to validate everything.– Thiago Henrique
@Ricardopunctual this option has not available in my version. It has the same Ignore.
– Thiago Henrique
@Thiagohenrique the
DoNotValidate
is available as of version 8, went to confirm :) http://docs.automapper.org/en/stable/8.0-Upgrade-Guide.html– Ricardo Pontual
@Ricardopunctual good. Thanks Ricardo.
– Thiago Henrique