Mapster from ExpandoObject to Dto - how to prevent setting missing keys to Null in Dto?

439 views Asked by At

I have an object representing an update:

var update = new ExpandoObject();
update.AddSafely("Name", "Mary");

This property is part of a dto, like:

public class Dto
{
  public string Name {get; set;}
  public string Other {get; set;
}

var data = new Dto { Name = "John", Other = "SomeData" };

Now when I map, all (other) properties not in the source dictionary are set to their default.

// Name = "Mary" but Other = null
update.Adapt(data);
1

There are 1 answers

0
Chaowlert Chaisrichalermpol On

You need to use IgnoreNullValues