views:

87

answers:

0

Imagine the following code:

return from a in DBContext.Acts
       join artist in DBContext.Artists
       on a.ArtistID equals artist.ID into art
       from artist in art.DefaultIfEmpty()
       select new Shared.DO.Act {
                 ID = a.ID,
                 Name = a.Name,
                 Artist = new Shared.DO.Artist   {
                             ID = artist.ID,
                             Name = artist.Name
                          },
                 GigId = a.GigID
              };

As you can see, the linqtosql generated act object is adapted into the Shared.DO.Act object. As part of this a linqtosql generated Artist object is adapted into a Shared.DO.Artist

Elsewhere in my code base, I may want to request an Artist (see below):

return from a in DBContext.Artists
       select new Shared.DO.Artist {
                 ID = artist.ID, 
                 Name = artist.Name
              },
              GigId = a.GigID
       };

This means the adption code for an Artist now appears in two places! Once when getting an artist and also when an act is loaded

How should I centralise this adaption code?