79613102

Date: 2025-05-08 20:15:03
Score: 0.5
Natty:
Report link

In Dapper, the order of columns matters when performing 1-to-many mappings using the Query method with multi-mapping. Here's what you need to know:

Id Column Position:

    • The split-on column (usually the Id) must appear first in the column sequence for each entity

    • Dapper splits rows when it sees a duplicate Id in this column.

      Proper Sequence Example:
      
      sql
      SELECT 
          u.Id, u.Name,  -- User columns (must start with Id)
          p.Id, p.Title, p.UserId  -- Post columns (must start with Id)
      FROM Users u
      JOIN Posts p ON u.Id = p.UserId
      
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: saibin