I have two entities :
public class TableA
{
public int id { get; set; }
public virtual TableB TableB { get; set; }
}
public class TableB
{
public TableB()
{
TableAList = new List<TableA>();
}
public int id { get; set; }
public virtual List<TableA> TableAList { get; set; }
}
And two classes
public class ClasseMetierA
{
private int id;
public ClasseMetierB TableB;
}
public class ClasseMetierB
{
public ClassMetierB()
{
TableAList = new List<ClasseMetierAList>();
}
private int id;
public List<ClasseMetierA> TableAList { get; set; }
}
I would like to convert TableB object into ClasseMetierB object. I'm using automapper with this configuration :
mapperConfig = new MapperConfiguration(cfg =>
{
cfg.CreateMap<TableA, ClasseMetierA>().MaxDepth(3);
cfg.CreateMap<TableB, ClasseMetierB>().MaxDepth(3);
});
mapperConfig.AssertConfigurationIsValid();
I'm calling this function to convert my object :
public B ConvertDTB(D obj)
{
var mapper = mapperConfig.CreateMapper();
return mapper.Map<B>(obj);
}
The problem is the following : When I convert an TableB object into a ClasseMetierB object, the properties of all the elements in TableAList are all null, even if the sources properties (TableB.TableAList) were not.
I found this post (Nested object members null after mapping with Automapper) with a similar problem but the solution given just raise a null exception error.
Thanks in advance