>Doesn't take care of if for me :-{
>If FirstOrDefault() returns null than trying to access any property of the expected type throws a NullReferenceException
Strange, maybe it doesn't where you tried? In Linq To SQL it works (internally creates a coalesce query):
void Main()
{
var data = from c in Customers
let first = c.Orders.FirstOrDefault()
let firstDet = first.OrderDetails.FirstOrDefault()
select new {
Customer = c.CustomerID,
City = first.ShipCity ?? "",
EmployeeFirst = first.Employee.FirstName ?? "",
OrderDetailFirst = firstDet.Product.ProductName ?? ""
};
data.Dump(); // LinqPad luxury
}