Entity Framework Lazy loading performance comparison The following code takes about 20 seconds to run with about 200,000 records in the TaskLogs table:

using (var db = new DAL.JobManagerEntities())
    {
        return db.TaskLogs.Select(taskLog =&gt; new TaskLog()
        {
            TaskLogID = taskLog.TaskLogID,
            TaskID = taskLog.TaskID,
            TaskDescription = taskLog.Task.TaskDescription,
            TaskType = (TaskType)taskLog.Task.TaskTypeID,
            RunID = taskLog.RunID,
            ProcessID = taskLog.ProcessID,
            JobID = taskLog.JobID,
            JobName = taskLog.Job.JobName,
            Result = taskLog.Result,
            StartTime = taskLog.StartTime,
            TimeTaken = taskLog.TimeTaken
        }).OrderByDescending(t =&gt; t.RunID).ThenByDescending(t =&gt; t.RunID).ThenByDescending(t =&gt; t.StartTime).ToList();
    }


I tweaked it until I got something that runs faster. Here's where I got to:

            using (var db = new DAL.JobManagerEntities())
    {
        db.Configuration.LazyLoadingEnabled = false;
        var tasks = db.Tasks.ToList();
        var jobs = db.Jobs.ToList();
        var result = db.TaskLogs.Select(x =&gt; new TaskLog()
        {
            TaskLogID = x.TaskLogID,
            TaskID = x.TaskID,
            RunID = x.RunID,
            ProcessID = x.ProcessID,
            JobID = x.JobID,
            Result = x.Result,
            StartTime = x.StartTime,
            TimeTaken = x.TimeTaken
        }).OrderByDescending(t =&gt; t.RunID).ThenByDescending(t =&gt; t.StartTime).ToList();

        foreach (var r in result)
        {
            r.TaskDescription = tasks.Single(t =&gt; t.TaskID == r.TaskID).TaskDescription;
            r.TaskType = (TaskType)tasks.Single(t =&gt; t.TaskID == r.TaskID).TaskTypeID;
            r.JobName = jobs.Single(j =&gt; j.JobID == r.JobID).JobName;
        }
        return result;}


Which runs in less than 6 seconds for the same number of records.

The TaskLog table is linked to the Job and Task tables as follows: 


The Job and Task tables will have 100s and 1000s of records respectively.

Is there anything else I could do in order to further improve the efficiency of the code?
1) Not sure if it impacts performance, but your first code fragment has one redunant order by:

.OrderByDescending(t =&gt; t.RunID).ThenByDescending(t =&gt; t.RunID)


2) You could improve performance of your seconds code with "client side indexing" (using a dictionary):

var tasksMap = tasks.ToDictionary(t =&gt; t.TaskID);
var jobsMap = jobs.ToDictionary(t =&gt; t.JobID);

foreach (var r in result)
{
    var task = tasksMap[r.TaskID];
    r.TaskDescription = task.TaskDescription;
    r.TaskType = (TaskType)task.TaskTypeID;
    r.JobName = jobsMap[r.JobID].JobName;
}