LINQ queries to generate a report on accrued work time on projects The following code fetches data from a MySql database to generate a simple report on accrued work time on projects.

I've been away from Entity Framework for a while and looking at this code you can see that the creation of ListProject is basically repeated 3 times.

Is there any way to refactor this so I can reuse the duplicate parts?

I've thought about a factory method, but that won't work because it can't be translated to SQL by the expression interpreter.

    var project = entities.Tickets
        .Where(p =&gt; p.ID == id)
        .Select(p =&gt; new ListProject
        {
            Id = p.ID,
            Name = p.ueberschrift,
            AssignedEmployee = new ListEmployee
            {
                Id = p.AssignedEmployee.ID,
                Name = p.AssignedEmployee.name
            },
            WorkUnits = p.WorkUnits
                .Select(wu =&gt; new ListProjectWorkUnit
                {
                    Duration = wu.dauer,
                    PauseDuration = wu.pauseDauer,
                    Employee = new ListEmployee
                    {
                        Id = wu.AssignedEmployee.ID,
                        Name = wu.AssignedEmployee.name
                    }
                })
                .ToList()
            })
            .Single();


    project.Tickets = entities.Tickets
        .Where(p =&gt; p.vonProjekt == id)
        .Where(p =&gt; p.phaseID == 0)
        .OrderBy(p =&gt; p.ueberschrift)
        .Select(p =&gt; new ListProject
        {
            Id = p.ID,
            Name = p.ueberschrift,
            AssignedEmployee = new ListEmployee
            {
                Id = p.AssignedEmployee.ID,
                Name = p.AssignedEmployee.name
            },
            WorkUnits = p.WorkUnits
                .Select(wu =&gt; new ListProjectWorkUnit
                {
                    Duration = wu.dauer,
                    PauseDuration = wu.pauseDauer,
                    Employee = new ListEmployee
                    {
                        Id = wu.AssignedEmployee.ID,
                        Name = wu.AssignedEmployee.name
                    }
                })
                .ToList()
        })
        .ToList();


    project.Phases = entities.projekt_phase
        .Where(p =&gt; p.projektID == id)
        .OrderBy(p =&gt; p.rang)
        .Select(p =&gt; new ListProjectPhase
        {
            Id = p.ID,
            Name = p.name,
            Tickets = p.Tickets
                .OrderBy(t =&gt; t.ueberschrift)
                .Select(t =&gt; new ListProject
                {
                    Name = t.ueberschrift,
                    Id = t.ID,
                    AssignedEmployee = new ListEmployee
                    {
                        Id = t.AssignedEmployee.ID,
                        Name = t.AssignedEmployee.name
                    },
                    WorkUnits = t.WorkUnits
                        .Select(wu =&gt; new ListProjectWorkUnit
                        {
                            Duration = wu.dauer,
                            PauseDuration = wu.pauseDauer,
                            Employee = new ListEmployee
                            {
                                Id = wu.AssignedEmployee.ID,
                                Name = wu.AssignedEmployee.name
                            }
                        })
                        .ToList()
                })
                .ToList()
        })
        .ToList();
I've thought about a factory method, but that won't work because it
  can't be translated to SQL by the expression interpreter.


Why don't you call (as suggested by t3chb0t) AsEnumerable() right before your factory method? You would perform the factory method in memory.

 var project = entities.Tickets
        .Where(p =&gt; p.ID == id)
        .AsEnumerable()   // &lt;-- loads the tickets into memory
        .Select(p =&gt; myFactoryMethod(p))
        .Single();