Limit A LINQ Left Join To One Row
Here is an example of using LINQ to return a List of all active Employees and their most current Mobile Phone number (if they have one). Check it out:
var query = (from emp in db.Employees
where emp.IsActive
let leftEmpPhone = db.EmployeePhones.Where(e =>
e.EmployeeID == emp.EmployeeID &&
e.PhoneTypeID == (int)PhoneTypeEnum.Mobile)
.OrderByDescending(e => e.CreateDate).FirstOrDefault()
select new
{
EmployeeID = emp.EmployeeID,
EmployeeMobilePhoneNumber = leftEmpPhone == null
? ""
: leftEmpPhone.PhoneNumber
}).ToList();