Skip to content

[C#] Implement N+1 Query Solution with EF Core Include #305

@davideme

Description

@davideme

Task

Implement the ?include= query parameter for eager loading in C#/Entity Framework Core.

Endpoints

  • GET /buildings with ?include=rooms or ?include=rooms.lamps
  • GET /buildings/{id} with ?include=rooms.lamps
  • GET /buildings/{id}/rooms with ?include=lamps
  • GET /rooms/{id} with ?include=lamps,building

Functional Requirement

Must minimize database queries regardless of the number of entities returned.

Implementation Hints

  • Use EF Core's .Include() and .ThenInclude() methods
  • Parse the include parameter and chain include calls dynamically
  • Example: context.Buildings.Include(b => b.Rooms).ThenInclude(r => r.Lamps)

Acceptance Criteria

  • ?include=rooms returns buildings with nested rooms
  • ?include=rooms.lamps returns buildings with rooms and lamps
  • Query count does not increase with number of buildings (verify with EF logging)

Parent Issue

Relates to #289

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions