-
I am looking for a clean way to map Create and LastModified to a Modified field when lastModified is null. public class Entity {
public DateTime Created { get; set; }
public DateTime? LastModified { get; set; }
}
public class EntityDTO {
public DateTime Created { get; set; }
public DateTime? LastModified { get; set; }
public DateTime Modified { get; set; }
}
// Want to map fields to something like this.
Modified = p.LastModified ?? p.Created; I was able to match it using before / after map [Mapper]
public partial class EntityMapper
{
private partial EntityDto _ToDto(Entity e);
[UserMapping(Default = true)]
public EntityDto ToDTO(Entity e)
{
var dto = _ToDto(e);
dto.Modified = e.LastModified ?? e.Created;
return dto;
}
}
public static partial IQueryable<EntityDto> ProjectToDTO(this IQueryable<Entity> q); Unfortunately with this way it does not work when calling it from IQueryable, any tips will be appreciated. |
Beta Was this translation helpful? Give feedback.
Answered by
latonz
Jul 16, 2024
Replies: 1 comment 1 reply
-
Have you tried using |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
jacokok
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Have you tried using
MapProperyFromSource.Use
, see docs?