Posted By

housecor on 11/21/10


Tagged


Versions (?)

LINQ outer join


 / Published in: C#
 

URL: http://www.hookedonlinq.com/OuterJoinSample.ashx

NOTE: When you do an outer join, every column selected that could be null from the join must have a ternary operator in the select statement.

  1. var allTeamMembers = from t in db.TeamMembers
  2. join ct in db.CaseTeamMembers on t.TeamMemberID equals ct.TeamMemberID into ctm
  3. from ct in ctm.DefaultIfEmpty()
  4. select new
  5. {
  6. CaseID = ct.CaseID == null ? 0 : ct.CaseID,
  7. t.TeamMemberID,
  8. CaseTeamMemberID = ct.CaseTeamMemberID == null ? 0 : ct.CaseTeamMemberID,
  9. t.Name,
  10. Photo = t.Photo ?? "default.gif"
  11. };

Report this snippet  

You need to login to post a comment.