-
Imagine the following tobe mapped. public partial class Class1
{
public int Id { get; set; }
public virtual ICollection<Class2> prop1 { get; set; } = new List<Class2>();
}
public partial class Class2
{
public string name { get; set; }
} The mapping: [Mapper(EnumMappingStrategy = EnumMappingStrategy.ByName, UseReferenceHandling = true, AllowNullPropertyAssignment = false)]
public static partial class DisableNullMapper
{
public static partial void MapClass1([MappingTarget] this Class1 target, Class1 input);
} What I would like to have the following behaviour on var input = new Class1(){prop1 = new List<Class2>()};
var target = new Class1(){prop1 = new List<Class2>()};
target.prop1.Add(new Class2());
//mapping
if(input.prop1.Any())
{
target.prop1 = input.prop1;
}
else
{
//do nothing
} In other words, I would like to only map from the source to the target, if the source collection property is not empty. I tried Can anyone please help me out? Thanks a lot! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This behavior—only assigning the collection if it is not empty—is currently not supported by Mapperly. |
Beta Was this translation helpful? Give feedback.
This behavior—only assigning the collection if it is not empty—is currently not supported by Mapperly.
What’s the use case or motivation behind wanting to skip the assignment if the collection is empty? Understanding your scenario better could help us think about potential workarounds or future feature ideas.