MapsterMapper / MapsterMapper/Mapster

Behaviour of `IMapper.Map(src, dst)` differs from AutoMapper

Open
#1,005 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
5.2k
Forks
410
Avg merge
2d 12h
Merged PRs (30d)
6

Description

I discovered a difference between AutoMapper's and Mapster's implementation of the IMapper interface. Even though it could be argued that the AutoMapper behavior is unintuitive, I believe that for compatibility, Mapster should update the values of the destination object too.

**AutoMapper**
```c#
var output = mapper.Map(from, to);
// output and to contain the mapped values
```

**Mapster**
```c#
var output = mapper.Map(from, to);
// only output contains the mapped values
```

**Risk**
The risk that this issue poses is that usages like [here](https://github.com/AutoMapper/AutoMapper.Collection.EFCore/blob/e173021f8e29f54124503d25918b362686a8c851/src/AutoMapper.Collection.EntityFrameworkCore/Persistence.cs#L101) do not map the value after switching to the Mapster implementation of `IMapper`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the IMapper.Map(src, dst) entry point and compare Mapster's behavior with the AutoMapper examples in the issue. Trace how the destination object is handled, then verify that both the returned value and the original destination contain the mapped values, ideally with a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.