Hi,
I have 2 tables, Employee and Absence. I want to do a left outer join so that I get all employees and any associated absences. In LINQ2SQL I can use the following to create the LEFT OUTER JOIN:
from e in Employees
join a in Absences on e.EmployeeID equals a.EmployeeID into ae
from x in ae.DefaultIfEmpty()
select new { FullName = e.Surname + ", " + e.Forename }
This is what I'm looking for but I want to show any absence start dates. I can change the select statement to
select new { FullName = e.Surname + ", " + e.Forename, x.StartDate }
but I get an error because DateTime is not nullable. How can I show an empty string if there is no StartDate or the actual Date if there is one? I tried using x.StartDate.ToShortDateString() but this obviously throws an error if it's null, I've also tried:
select new {Surname = e.Surname, StartDate = x.StartDate == null ? "" : x.StartDate }
but this doesn't work either. Any suggestions?