Problem to ignore null values and members when use mapster in my blazor project

65 views Asked by At

I have 2 objects. the first one is my dto model and the second one is my real entity. Of course, my dto model does not have all properties of my entity. So when i use Adapt method to transfer values from my dto to entity, the rest of properties which does not exists in my dto model sets to null!

I've googled alot and found some tips to ignore null values or ignore Members, but nothing worked!!

Here is my sample code :

var config = new TypeAdapterConfig();
config.NewConfig<RelationDTO, CRM_CustomerRelation>()
    .IgnoreNullValues(true);
config.ForType<RelationDTO, CRM_CustomerRelation>()
    .IgnoreMember((member, side) => member.Name == "SortID"
        || member.Name == "CreatedBy"
        || member.Name == "DateCreated"
        || member.Name == "TimeCreated");
CRM_CustomerRelation relation;
if(isNewMode)
{
    // ...
}
else
{
    // ... Get  relation from database
     relation = relationDto.Adapt<CRM_CustomerRelation>(config); // after call this method, all above members sets to null!
}

Where is my problem and how to solve it? Thanks in advance

0

There are 0 answers