Mapping across Linq to SQL relations

May 25, 2010 at 3:54 PM
This is a simplified example of my app but basically.............. Say I have Customer, Order and Product in a database and the corresponding entity classes from Linq To SQL. I also have a CustomerDTO, OrdersDTO and ProductsDTO (for use in the ASP.NET views) which have relations between each other as well. If I get a Customer entity from Linq To SQL and I know I want to show all of the orders in the view I would like to automatically map from Customer to CustomerDTO but also copy Customer.Orders into CustomerDTO.Orders (which is of type List<OrderDTO>) What's the best way of doing this? For the time being I'm iterating over the Customer.Orders collection and mapping one at a time but it seems to me that it should be possible to do it all it one go, possibly by specifying an inner Mapper??? Also, at some point I'm going to want to map all 3 tables together (and possibly more in the future) but assume this should just be an extension of the 2 entity situation. Thanks, Mark