Currently I'm searching for a good object-to-object mapper for entity --> dto, dto --> entity (in general I would reload the entity from database and assign some properties from my dto. So a bidirectional mapper would be great.
I've found automapper which would suite my needs except for being bidirectional. And as they say it will never be. So I did some further searching and found Glue.
Just some questions:
- In automapper you would do something like
IList<Article> articlelist = [DB-Access];
IList<ArticleDTO> listart = Mapper.Map(articlelist);
So you just define the Mapping for Entity-DTO and then you transform a list of your entities to a complete list of your DTOs.
Is this possible with glue? I tried a direct map, but it didn't work as expected.
- With automapper you could also do projections of your sql. (with linq)
IQueryable<Article> domainquery = [do some linq];
IQueryable<ArticleDTO> dtoquery = domainquery.Project().To<ARTICLEDTO>();
So it would only query fields you need from your db. So it is a lot faster (even if you use things like lazy loading with NHibernate, ...). Is there something similar in glue?
Thanks in advance!
Nov 2, 2011 at 7:16 PM
1. This can be done with something like this:
I just checked in a complete example : http://glue.codeplex.com/SourceControl/changeset/view/70798#1274908
var mapper = new Mapping<Article, ArticleDTO>();
IList<ArticleDTO> articleDTOs = new List<ArticleDTO>();
foreach (var article in articles)
2. Glue has not digged into Linq yet, unfortunately.
Hope this helps!