This project is read-only.

Some questions (List Mapping, Linq Projections)

Oct 29, 2011 at 10:51 PM

Hi!

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:

  1. In automapper you would do something like
    Mapper.CreateMap<Article, ArticleDTO>();
    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.
  2. 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>();
    return dtoquery.ToList();
    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 8:16 PM

Hi,

1. This can be done with something like this:

var mapper = new Mapping<Article, ArticleDTO>();
mapper.AutoRelateEqualNames();
IList<ArticleDTO> articleDTOs = new List<ArticleDTO>();
foreach (var article in articles)
{
    articleDTOs.Add(mapper.Map(article));
}
I just checked in a complete example : http://glue.codeplex.com/SourceControl/changeset/view/70798#1274908

 

2. Glue has not digged into Linq yet, unfortunately.

 

Hope this helps!