Retrieve Tasks by Employee I think I've done a decent job keeping this query simple and understandable, but I'd like to know if you have some more advice.

My relevant entities are defined like this:

public class Task
{
    [ForeignKey("Employee")]
    public string EmployeeId { get; set; }
    public Employee Employee { get; set; }

    [Required]
    [ForeignKey("Status")]
    public int StatusId { get; set; }
    public TaskStatus Status { get; set; }

    [...]
}

public class Employee
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    [Required]
    [MaxLength(10)]
    [Index(IsUnique=true)]
    public string EmployeeId { get; set; }

    [Required]
    [StringLength(100)]
    public string FirstName { get; set; }

    [Required]
    [StringLength(100)]
    [DisplayName("Last name")]
    public string LastName { get; set; }

    [...]
}

public class TaskStatus
{
    [Key]
    public int Id { get; set; }

    [Required]
    [MaxLength(50)]
    public string Name { get; set; }

    [...]
}


I've stripped off what I believe are irrelevant parts of the entities.

The query itself is following:

// Retrieves all tasks from the database. We filter the tasks on 3 different criteria. Since all 3 criteria
// must be fulfilled for the task to be displayed, we use logical and to concatenate them.
// 
// The first criteria is the search term. If the search term is empty, we don't filter out any tasks, so 
// that is the first check we make. Also, we test if the FistName, LastName or the EmployeeId contain the 
// search term.
//
// Next criteria is the status filter. We keep the tasks that have the right status, or all tasks if the 
// given status is null.
//
// The last criteria is employee filter, and the logic is the same as for the status filter.
var tasks = db.Tasks
    .Include(t =&gt; t.Employee)
    .Include(t =&gt; t.Status)
    .Where(t =&gt;
        (
            search == null
            || t.Employee.FirstName.Contains(search)
            || t.Employee.LastName.Contains(search)
            || t.Employee.EmployeeId.Contains(search)
        )
        &amp;&amp; ((statusFilter == null) || (t.StatusId == statusFilter.Value))
        &amp;&amp; ((employeeFilter == null) || (t.EmployeeId == employeeFilter))
    );


The query does what it is supposed to do, it filters the task list properly on all 3 parameters. I'm just worried that it is a little too unreadable (too tricky), especially since my colleagues are mostly young and inexperienced.
Remove the additional ()s in the statusFilter and employeeFilter lines as they are unnecessary.
Indent the statusFilter and employeeFilter lines so that they are symmetrical with the search lines.
Change search to be searchTerm as it is more specific.  search by itself could mean anything like a stored query, a boolean value, etc.
As per Magus' comment you can change t to task since it is more clear and will not add space that starts pushing statements across extra lines.




var tasks = db.Tasks
  .Include(task =&gt; task.Employee)
  .Include(task =&gt; task.Status)
  .Where(task =&gt;
    (
      searchTerm == null || 
      task.Employee.FirstName.Contains(searchTerm) ||
      task.Employee.LastName.Contains(searchTerm) ||
      task.Employee.EmployeeId.Contains(searchTerm)
    ) &amp;&amp;
    (
      statusFilter == null || 
      task.StatusId = statusFilter.Value
    ) &amp;&amp;
    (
      employeeFilter == null || 
      task.EmployeeId == employeeFilter
    )
);