Exception "The source and destination types must be the same" when converting nullable property to non Nullable
ahmedeltabee opened this issue · 1 comments
ahmedeltabee commented
can't convert nullable to non nullable using expression mapping
here is the code :
Model { public Guid Id { get; set; } }
Dto {public Guid? Id { get; set; } }
Service layer {
public async Task GetFirstOrDefaultAsync(Expression<Func<TDto, bool>> dtoPredicate)
{
var predicate = Mapper.MapExpression<Expression<Func<T, bool>>>(dtoPredicate);
var result = await Repository.FirstOrDefaultAsync(predicate);
var dtoResult = Mapper.Map(result);
return dtoResult ;
}
}
expection : Message =The source and destination types must be the same for expression mapping between literal types. Source Type: Guid, Source Description: Id, Destination Type: Nullable`1, Destination Property: Id.
BlaiseD commented
That's an expected exception thrown by this library.
Here's how it is designed to be used.