Sql – Mapping Linq-to-Sql entities to custom domain entities

dnsdomain-driven-designlinq-to-sqlmapping

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?

Best Answer

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: