dogusteknoloji / batmap Goto Github PK
View Code? Open in Web Editor NEW๐ฆ Convention-based, fast object mapper.
Home Page: https://dogusteknoloji.github.io/BatMap/
License: MIT License
๐ฆ Convention-based, fast object mapper.
Home Page: https://dogusteknoloji.github.io/BatMap/
License: MIT License
It's a bit strange that HandWritten
is not the first. BatMap
is a really nice project, but benchmark result looks a bit strange. Looks like HandWritten
sample has a bug, yes it's possible to do this kind of mapping but it's a bit inefficient. try to use ConverAll
method, it'll remove all ToList
methods (except one, IList does not have ConvertAll
like this
public void HandWritten()
{
var customerDTOs = _customers.Select(c => new CustomerDTO
{
Id = c.Id,
Addresses = c.Addresses.ConvertAll(a => new AddressDTO
{
City = new CityDTO
{
Id = a.City.Id,
Name = a.City.Name,
Population = a.City.Population
},
Detail = a.Detail,
Id = a.Id
}),
CompanyName = c.CompanyName,
Endorsement = c.Endorsement,
Orders = c.Orders.ConvertAll(o => new OrderDTO
{
Id = o.Id,
OrderDetails = o.OrderDetails.ConvertAll(od => new OrderDetailDTO
{
Id = od.Id,
Count = od.Count,
UnitPrice = od.UnitPrice
}),
OrderNo = o.OrderNo,
Price = o.Price
}),
Phone = c.Phone
}).ToList();
}
BTW, I think other mappers support collection mapping, so it's possible to map without ToList
For instance, there's no Select
public void BatMap() {
var customerDTOs = _customers.Map<Customer, CustomerDTO>().ToList();
}
but here's Select
and ToList
[Benchmark]
public void TinyMapper() {
var customerDTOs = _customers.Select(c => Nelibur.ObjectMapper.TinyMapper.Map<Customer, CustomerDTO>(c)).ToList();
}
[Benchmark]
public void ExpressMapper() {
var customerDTOs = _customers.Select(c => global::ExpressMapper.Mapper.Map<Customer, CustomerDTO>(c)).ToList();
}
for any performance comparisonce, it's really impotant compare the same things in an equeal environment.
1.1.3 (from NuGet)
Mapper.RegisterMap(typeof(MyEntity), typeof(MyDto)); // MyDto doesn't have parameterless public ctor
var dto = Mapper.Map<MyEntity, MyDto>(new MyEntity(1, "Bla"));
dto.Id.Equals(1);
dto.Name.Equals("Bla");
dto.Id.Equals(0);
dto.Name.Equals(string.Empty);
apply mapping to an existing object.
possible use-case
user posts an update (using a DTO) to an existing object. the service loads the existing object from the DB, and then use the map(dto, entity) to apply the updates as required.
Example Usage
public void Update(PersonDto personDto) {
var person = _session.Get<Person>(personDto.id);
_mapper.Map(personDto, person);
}
note that the dto may only contain a subset of the entity properties
how to get the different fields/properies when before/after mapped ?
how to got the mapped result is that update some fields/properies ?
same question mark in agileobjects/AgileMapper#229
Reported by: tungtrungvn
1.1.12
It happens when we use "new" keyword to hide property from parent class
Should use property from inherited class
Throws "Ambiguous match found" exception
1.1.2
Using ThenInclude with queries
Should map all Include and ThenInclude navigations
Only maps Include navigations, skips ThenInclude navigations
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.