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

Created on 30 Oct 2018  路  1Comment  路  Source: StackExchange/Dapper

Hello. I'm beginner and don't know fuctionality of this great component.
Can someone help me with reading data to object model
```c#
public class Order
{
public int OrderId { get; set; }
public DateTime Date { get; set; }
public List Details { get; set; }
}
public class Detail
{
public int OrderId { get; set; }
public string Product { get; set; }
}

```sql
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((o, d) => { o.Details.Add(d); return o; }, splitOn:"OrderId");
But it returns in collection duplicate records

Most helpful comment

Hello,

This example may help you:
https://github.com/doc212/dapper-issue-1151/blob/master/Program.cs

It's taken mostly from here (One to Many)
https://dapper-tutorial.net/result-multi-mapping

If it does not help you, could you clarify what you mean by :

But it returns in collection duplicate records

And maybe provide a more complete example

Also I think this kind of question fits better in StackOverflow (but that's just my opinion)

Cheers.

>All comments

Hello,

This example may help you:
https://github.com/doc212/dapper-issue-1151/blob/master/Program.cs

It's taken mostly from here (One to Many)
https://dapper-tutorial.net/result-multi-mapping

If it does not help you, could you clarify what you mean by :

But it returns in collection duplicate records

And maybe provide a more complete example

Also I think this kind of question fits better in StackOverflow (but that's just my opinion)

Cheers.

Was this page helpful?
0 / 5 - 0 ratings