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

Meaning of mapping to an existing object? #430

Open
zhenlei520 opened this issue Apr 27, 2022 · 1 comment
Open

Meaning of mapping to an existing object? #430

zhenlei520 opened this issue Apr 27, 2022 · 1 comment

Comments

@zhenlei520
Copy link

zhenlei520 commented Apr 27, 2022

Meaning of mapping to an existing object?

I used map to existing object, but I found that it doesn't preserve the value of the existing object during the mapping process, it initializes the value of the existing object, and when the existing object is a collection, the value of the existing object is the same as The response data is not the same, but I think their result should be the same

[TestMethod]
public void TestMapToExistingObject()
{
    List<UserDto> sources = new List<UserDto>()
    {
        new()
        {
            Name = "Jim",
            Age = 18
        }
    };

    List<UserDto> destination = new List<UserDto>();
    sources.Adapt(destination);
    Assert.IsTrue(destination.Count == sources.Count);//But it is not established at present, I think he is a bug
}

public class UserDto
{
    public string Name { get; set; }

    public int Age { get; set; }
}
@sgf
Copy link

sgf commented Nov 9, 2022

update existing colliection
i think Mapster need add new api something like ByField() (search some key to update)
,and insert new when not exists.

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

2 participants