I have a following class structure:
public class A
{
public bool Property1 { get; set; }
public bool Property2 { get; set; }
}
public class ContainerForA
{
public A A { get; set; }
}
public class A1
{
public bool Property1 { get; set; }
}
public class ContainerForA1
{
public A1 A { get; set; }
}
I create a mapping for this set of classes:
Mapper.CreateMap<A1, A>();
Mapper.CreateMap<ContainerForA1, ContainerForA>();
I create an instance of this set of classes:
var cnt_a = new ContainerForA()
{
A = new A()
{
Property1 = false,
Property2 = true
}
};
var cnt_a1 = new ContainerForA1()
{
A = new A1()
{
Property1 = true
}
};
If I call Mapper.Map(cnt_a1.A, cnt_a.A)
I'm getting the result I was expecting: both properties (Property1
and Property2
) of object cnt_a are true
But if I call Mapper.Map(cnt_a1, cnt_a)
I'm getting true for Property1
and false for Property2
. Could someone explain me why? And is there any option for me to declare my mappings in the way so I won't lose properties that are present in my destination object but are NOT in my source object?