0

I'm trying to retrieve both the list of ProjectCategories (subcategories) and the Categorie of a ProjectCategorie, the sub lists are retrieved. But I have no idea how to get the Categorie.

Project project = ctx.Projecten.Include(p => p.ProjectCategories.Select(s => s.Sub.Select(su => su.Sub))).ToList().Find(p => p.ProjectId == projectId);

These are the domain classes, as you can see I have a Categorie inside my ProjectCategorie:

public class ProjectCategorie
{
    public int ProjectCategorieId { get; set; }
    public double MinBedrag { get; set; }
    public double MaxBedrag { get; set; }
    public bool Aanpasbaar { get; set; }
    public bool AutoAanpasbaar { get; set; }

    public ProjectCategorie Super { get; set; }
    public List<ProjectCategorie> Sub { get; set; }
    public Project Project { get; set; }
    public Categorie Categorie { get; set; }
}

public class Categorie : BegrotingsPost
{

    public int CategorieId { get; set; }
    public string Beschrijving { get; set; }
    public double MinBedrag { get; set; }
    public double MaxBedrag { get; set; }

    public Begroting Begroting { get; set; }
    public BegrotingsPost Super { get; set; }
}
Michiel
  • 103
  • 1
  • 11

1 Answers1

9

Ok update (mis read the question) ...

Project project = ctx.Projecten
   .Include(p => p.ProjectCategories.Select(s => s.Sub.Select(su => su.Sub)))
   .Include(p => p.ProjectCategories.Select(s => s.Categorie))
   .Find(p => p.ProjectId == projectId)
   .ToList();

I would probably do the find in the db too (might introduce a logic error else). Just moving the ToList() to the last line of the query will resolve that.

War
  • 8,539
  • 4
  • 46
  • 98
  • Like I said, the subs are retrieved, I need to be able to retrieve the Categorie for the ProjectCategorie too, but I don't know how – Michiel Apr 22 '16 at 12:16
  • 1
    ah ok ... add another include ... hang tight i'll update my answer – War Apr 22 '16 at 12:18