I'm trying to map a class Function
to another one called FunctionDTO
using AutoMapper
. The classes look like this:
public class Function
{
...
public int MasterFunctionId { get; set; }
public Function MasterFunction { get; set; }
...
}
public class FunctionDTO
{
...
public int MasterFunctionId { get; set; }
public FunctionDTO MasterFunction { get; set; }
...
}
The mapping works perfectly for properties such as MasterFunctionId
, but MasterFunction
is always null, even when the Function
object has a value in that property.
The call to the mapper is done in the following way (P.S. the variable config is injected into the class):
query.ProjectTo<FunctionModel>(config)
I can't use the following because the I get an error message, probably because Mapper is not initialized:
CreateMap<FLHFunction, FunctionModel>()
.ForMember(f => f.PRNummerMaster, opt => opt.MapFrom(src => Mapper.Map<FLHFunction, FunctionModel>(src)));
Is there any way I can configure the mapping in order to make this work? I tried similar solutions to my last piece of code, but I must be missing something.