views:

465

answers:

2

How could I map my Linq-to-Sql generated entities (DTO’s) to my domain entities? The problem is that I can’t map the associations because they are not of the same type. The DTO’s uses EntitySet and EntityRef and my domain entities uses IList and T.

I’ve looked at some blog post: Ian Cooper's architecting-linq-to-sql-applications-part-5 and digital_ruminations linq-to-sql-poco-support but they don’t fit my needs. I like some kind of generic converter class to handle the mapping.

Now I do something like this:

public IList<Entities.Customer> GetAll()
    {
        try
        {
            return _custConverter.Convert(base.GetEntities());
        }

But the Convert method only converts the basic properties not the associations. Any ideas how I can do this the best way?

+2  A: 

You might want to look into AutoMapper. It does a great job of mapping properties automatically out of the box and supports extensive customization, such as custom converters, which I think could be used to make Lists out of your EntitySets.


Update:

Lucas
http://code.google.com/p/automapperhome/source/browse/trunk/src/AutoMapperSamples/DynamicMapping.cs is probably what he's looking for.
Todd Smith
@Todd: Thanks, but the project site *is* on CodePlex. However, I updated my answer with new links to code repository, discussion groups, and blog post.
Lucas
A: 

Thanx, I'll look at this. It sounds promising

related questions