Skip to content

If a property in the source list does not exists its value is set null in the destination #3965

@cam92yz

Description

@cam92yz

Hello

We updated AutoMapper to version 11. After the upgrade we faced the problem that the AutoMapper sets a property to null if it does not exist in the source class. The behavior was only recognized in lists.

`

    var mapper = new AutoMapper.Mapper(mapperConfig);

    var destination = new Destination();
    destination.Group = new Group();
    destination.Definitions = new List<Definition>();
    destination.Definitions.Add(new Definition() { Group = new Group() });

    var source = new Source();
    source.Definitions = new List<BusinessDefinition>();
    source.Definitions.Add(new BusinessDefinition());
    mapper.Map(source, destination);

    var x = destination.Definitions[0].Group; // The property does not exist on the BusinessDefinition class. After mapping the "Group" property is null, i expect that the property keeps its value. 
    var z = destination.Group; // This property does not exist in the "Source" class. After mapping the value did not change in this case.

`

ConsoleApp7.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions