mapping-with-mapperly
Skill1 starsChanged 6 days agoMITView on GitHub
How database models map to Application entities with the Mapperly source generator, including ignored members and RMG warnings. Use when adding a property to a model or entity, or adding a new mapping.
In this repository40 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- add-a-use-caseSkill
- api-conventionsSkill
- branches-and-pull-requestsSkill
- cancellationSkill
- ci-for-your-solutionSkill
- ci-pipelineSkill
- clean-architecture-layersSkill
- configuration-and-environmentsSkill
- coverageSkill
- csharp-house-styleSkill
- data-access-ef-coreSkill
- database-migrationsSkill
- docker-and-composeSkill
- docs-and-voiceSkill
- errors-and-exceptionsSkill
- expose-a-use-caseSkill
- family-syncSkill
- health-checksSkill
- integration-testsSkill
- json-serializationSkill
- mcp-inspectorSkill
- mediatorSkill
- optional-token-authSkill
- packages-and-dependenciesSkill
- pagingSkill
- presentation-integration-testsSkill
- releasesSkill
- sample-dataSkill
- security-findingsSkill
- serilogSkill
- telemetrySkill
- template-authoringSkill
- test-designSkill
- time-providerSkill
- unit-testsSkill
- validationSkill
- writing-a-skillSkill
- xml-docs-and-openapiSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 18
Add the property to both sides with the same name.
- Very specific: line 21
Use the aliases at the top of the mapper (AppMovie, InfraMovie) so it's always clear which side is which.
- Distinctive: line 39
Use AutoMapper. It's commercially licensed now, and it maps by reflection at runtime.
- Distinctive: line 40
Write a mapping by hand when Mapperly can generate it.
- Very specific: line 41
Add <NoWarn> for RMG codes.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Mapping with Mapperly
The rule
Mapping code is generated at compile time by Mapperly (Riok.Mapperly), never written by hand and never done by reflection. Infrastructure's MovieReviewsMapper (src/Infrastructure/Databases/MovieReviews/Mapping/MovieReviewsMapper.cs) maps database models to Application entities. It only maps that way, because writes build the database model directly (data-access-ef-core). Add a mapping in the other direction only when something calls it. Presentation layers that need their own response models have their own mapper beside them.
Mapperly reports unmapped members as RMG warnings, and warnings fail the build, so every member is either mapped or explicitly ignored.
Steps
- Add the property to both sides with the same name. Mapperly maps it with no other change.
- A property that only exists on one side gets
[MapperIgnoreSource(nameof(...))](it's on the source only) or[MapperIgnoreTarget(nameof(...))](on the target only) on each affected method. - Different names on purpose? Use
[MapProperty(nameof(Source.A), nameof(Target.B))]. - Use the aliases at the top of the mapper (
AppMovie,InfraMovie) so it's always clear which side is which. - Build. Fix every
RMGwarning rather than suppressing it.
Example
// src/Infrastructure/Databases/MovieReviews/Mapping/MovieReviewsMapper.cs
[Mapper]
internal partial class MovieReviewsMapper
{
[MapperIgnoreSource(nameof(InfraMovie.DateCreated))]
[MapperIgnoreSource(nameof(InfraMovie.DateModified))]
public partial AppMovie ToDomain(InfraMovie movie);
}Don't
- Use AutoMapper. It's commercially licensed now, and it maps by reflection at runtime.
- Write a mapping by hand when Mapperly can generate it.
- Add
<NoWarn>forRMGcodes. - Map in a handler. Repositories return entities already mapped.
Check
dotnet buildDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

