Users Pricing

forum

Home Forums Mapping complex nested Dapper results to C# objects – MindStick

Mapping complex nested Dapper results to C# objects

John Smith 68 30 Sep 2026

I'm struggling with a query that returns a parent row and a variable number of child rows in a single flat result set. Dapper is great for simple 1:1 mappings, but here I need to group children under their parent dynamically.

For example, a Departments table joined to Employees where each department has zero or more employees. I don't want to run N+1 queries. My first thought was to use multiple result sets, but my SQL only returns one.

What patterns do people use? I've seen references to custom multi-mapping with Query<T, U, T>, but the syntax looks intimidating. Is there a cleaner way, perhaps by splitting the flat list in memory after a single query?

If someone could share a minimal working example of splitting a flat Dapper result into a parent-child hierarchy, that would save me hours of trial and error.


0 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md