views:

28

answers:

1

How can I do this, ie keep the mapping separate?

Instead of this:

var people= (from p in db.people select new Person{ 
                                              id=p.id,
                                              name=p.name
                                               }).ToList();

I want to do this:

 var people= (from p is db.people select new Person {
                                        ***MAPTODOMAIN(p)*** 
                                         }).ToList();
+1  A: 

Assuming that Person in your model is a domain class that is not in the Linq2SQL data context and substituting the class AppUser as the class that is in the data context (for clarity as the names were very similar in your example), something like this would work:

 var people = (from p in db.AppUsers select MapPerson(p)).ToList();

which uses a method similar to this somewhere else in the code:

 private Person MapPerson(AppUser user)
 {
     return new Person {Id = user.Id, Name = user.Name};
 }
Steve Willcock