So I have 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
};
This loads an act object and adapts it from a linq object to my domain act object.
As you can see I have defined an outer join on the artist to act relationship.
I have done this because I always want the act, irrespective of if it has an artist.
This works really well if the act does indeed have an artist.
If it doesnt then the code dies. This is the the culprit:
Artist = new Shared.DO.Artist
{
ID = artist.ID,
Name = artist.Name
},
If I remove it, its fine. Is it possible to do what I'm attempting?