Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New object is created on destination instead of null when using Adapt<> #693

Open
nikitabraganov opened this issue Apr 9, 2024 · 2 comments

Comments

@nikitabraganov
Copy link

nikitabraganov commented Apr 9, 2024

I have the following classes:

ScheduleWrapper

 public Guid ID { get; set; }  
 public Guid? CompanyID { get; set; }  
 public CItyWrapper City {get;set;}  
 public CItyWrapper City1 {get;set;}  

Schedule

 public Guid ID { get; set; }
 public Guid? CompanyID { get; set; }
 public Company Company { get; set; }
 public CIty Start{get;set;}
 public CIty End {get;set;}

When I try to adapt ScheduleWrapper to Schedule, on Schedule an empty Company object will be created instead of null.

Other configurations are:

config.Default.PreserveReference(true);
config.Default.IgnoreNullValues(true);
config.NewConfig<Schedule, ScheduleWrapper>().TwoWays()
                .Map(dest => dest.City, src => src.Start)
                .Map(dest => dest.City1, src => src.End);

I noticed this behavior also in other places where the explicit mapping is not defined.

Is there a setting to not create empty objects on destination when it not exists on source?

@nikitabraganov
Copy link
Author

I migrated from AutoMapper, and there I had the "AllowNullDestinationValues" property on the MapperConfiguration.

@nikitabraganov
Copy link
Author

@andrerav

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant