DapperLib / DapperLib/Dapper

How I can read Parent - Child DataSet into object structure (If it possible)

Open
#1,151 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
18.4k
Forks
3.7k
Avg merge
5h 8m
Merged PRs (30d)
1

Description

Hello. I'm beginner and don't know fuctionality of this great component.
Can someone help me with reading data to object model

    public class Order
    {
        public int OrderId { get; set; }
        public DateTime Date { get; set; }
        public List<Detail> Details { get; set; }
    }
    public class Detail
    {
        public int OrderId { get; set; }
        public string Product { get; set; }
    }
SELECT O.OrderId, O.DateTime, D.Product
FROM Orders O
INNER JOIN Details D ON D.OrderId=O.OrderId

May be I should do so?
var x = multi.Read<Order, Detail, Order>((o, d) => { o.Details.Add(d); return o; }, splitOn:"OrderId");
But it returns in collection duplicate records

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the Order and Detail models, joined SQL query, and proposed multi.Read<Order, Detail, Order> call with splitOn:"OrderId". Start with Dapper's multi-mapping documentation and examples; done means clarifying how the joined rows should map into the object structure and why duplicate records appear.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
backend, database
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.