https://github.com/dogusteknoloji/batmap
🦇 Convention-based, fast object mapper.
https://github.com/dogusteknoloji/batmap
dto entity mapper mapping projector
Last synced: about 1 year ago
JSON representation
🦇 Convention-based, fast object mapper.
- Host: GitHub
- URL: https://github.com/dogusteknoloji/batmap
- Owner: DogusTeknoloji
- License: mit
- Created: 2017-04-11T19:46:10.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-02-06T13:42:53.000Z (about 3 years ago)
- Last Synced: 2025-04-08T09:49:30.786Z (about 1 year ago)
- Topics: dto, entity, mapper, mapping, projector
- Language: C#
- Homepage: https://dogusteknoloji.github.io/BatMap/
- Size: 189 KB
- Stars: 220
- Watchers: 30
- Forks: 26
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# BatMap - The Mapper we deserve, not the one we need.
**Opininated (yet another) mapper, mainly to convert between EF Entities and DTOs.**
Supports .Net Standard 1.0.
[](https://ci.appveyor.com/project/DogusTeknoloji/batmap)
[](https://coveralls.io/github/DogusTeknoloji/BatMap?branch=master)
[](https://www.nuget.org/packages/BatMap/)
[](https://gitter.im/NaNaNaNaBatMap/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[](https://github.com/DogusTeknoloji/BatMap/issues)
[](https://raw.githubusercontent.com/DogusTeknoloji/BatMap/master/LICENSE)
[](https://github.com/DogusTeknoloji/BatMap)
[](https://github.com/DogusTeknoloji/BatMap)
Let's first obey the number one rule for mappers, a benchmark (using [BenchmarkDotNet](http://benchmarkdotnet.org/)):
| Method | Mean |
|-------------- |---------:|
| HandWritten | 1.143 ms |
| BatMap :boom: | 2.000 ms |
| SafeMapper | 2.933 ms |
| Mapster | 2.942 ms |
| AutoMapper | 3.497 ms |
| TinyMapper | 4.172 ms |
| ExpressMapper | 6.955 ms |
| FastMapper | 9.203 ms |
Results may (probably) vary. Latest run can bee seen on [Appveyor Build](https://ci.appveyor.com/project/DogusTeknoloji/batmap).
* Fast (enough)
* NOT over-engineered, code is really simple
* Instantiatable mapper
* Convention based, zero configuration static shortcut exists too (obviously named Mapper)
* Does not crash when faced with circular-dependencies during registration
* In fact, can resolve recurring instances to same target instance (yaay no StackOverflowException!)
* Can project IQueryable\ to IQueryable\ with respect to includes (via auto-detection or with custom parameters)
* and much more...
## API
Registration with static API:
```csharp
Mapper.RegisterMap();
```
or use an instance:
```csharp
var mapper = new MapConfiguration(dynamicMapping: DynamicMapping.MapAndCache, preserveReferences: true);
mapper.RegisterMap();
```
Note: You don't have to register type mappings when using a MapConfiguration with Dynamic Mapping enabled (like the static API uses).
You can customize expressions for members:
```csharp
mapper.RegisterMap(b => b.MapMember(o => o.Price, (o, mc) => o.Count * o.UnitPrice));
```
Map an object:
```csharp
Mapper.Map(customer);
```
Map an enumerable:
```csharp
customers.MapTo(preserveReferences: true); // extension methods FTW!
```
Project a query:
```csharp
customerQuery.ProjectTo(checkIncludes: true);
```
or with expanding specific navigations:
```csharp
customerQuery.ProjectTo(c => c.Addresses, c => c.Orders);
```
Note: If you want to change mapping behavior, create a class that inherits from ExpressionProvider, override CreateMemberBinding and inject an instance of your class to MapConfiguration.
## Where can I get it?
You can install [BatMap](https://www.nuget.org/packages/BatMap/) from the package manager console:
```
PM> Install-Package BatMap
```
## Documentation
You might want to visit [wiki](https://github.com/DogusTeknoloji/BatMap/wiki) for more.
***
Developed with :heart: at [DoÄŸuÅŸ Teknoloji](http://www.d-teknoloji.com.tr).