Skip to the content.

BatMap - The Mapper we deserve, not the one we need.

🦇 BatMap Opininated (yet another) mapper, mainly to convert between EF Entities and DTOs.

Supports .Net Standard 1.0.

Build status Coverage Status NuGet Badge Join the chat at https://gitter.im/NaNaNaNaBatMap/Lobby GitHub issues GitHub license

GitHub stars GitHub forks

Let’s first obey the number one rule for mappers, a benchmark (using BenchmarkDotNet):

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.

API

Registration with static API:

Mapper.RegisterMap<Customer, CustomerDTO>();

or use an instance:

var mapper = new MapConfiguration(dynamicMapping: DynamicMapping.MapAndCache, preserveReferences: true);
mapper.RegisterMap<Customer, CustomerDTO>();

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:

mapper.RegisterMap<Order, OrderDTO>(b => b.MapMember(o => o.Price, (o, mc) => o.Count * o.UnitPrice));

Map an object:

Mapper.Map<CustomerDTO>(customer);

Map an enumerable:

customers.MapTo<Customer, CustomerDTO>(preserveReferences: true);  // extension methods FTW!

Project a query:

customerQuery.ProjectTo<CustomerDTO>(checkIncludes: true);

or with expanding specific navigations:

customerQuery.ProjectTo<Customer, CustomerDTO>(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 from the package manager console:

PM> Install-Package BatMap

Documentation

You might want to visit wiki for more.


Developed with :heart: at DoÄŸuÅŸ Teknoloji.