I am mapping source object
public class PlannedCare
{
public int OrderNumber { get; set; }
public PlannedCareBatch? BatchStart { get; set; }
}
to
public class PlannedCareDto
{
public int OrderNumber { get; set; }
public PlannedCareBatchRm? BatchStart { get; set; }
}
Config:
var config = new MapperConfiguration(cfg => {
cfg.AllowNullDestinationValues = true; //this is default, but just to make sure...
cfg.CreateMap<PlannedCare, PlannedCareRm>();
cfg.CreateMap<PlannedCareBatch, PlannedCareBatchRm>();
// other mappings...
});
All is OK if I use Map
method. When I use ProjectTo
the destination BatchStart object is always initialized. I want it to remain null if source property BatchStart is null. I am using Mongo DB driver. Where is the problem?
public IQueryable<PlannedCareDto> GetQueryable()
{
return _collection
.AsQueryable()
.ProjectTo<PlannedCareDto>(_mapper.ConfigurationProvider);
}
I even tried setting NullSubstitue on property, which also does not work. I guess the query will be somehow malformed…
CreateMap<PlannedCare, PlannedCareRm>()
.ForMember(p => p.BatchStart, d => d.NullSubstitute(null));