I\'ve got three classes User, Order & Project which are stored in single tables. The orders and projects both have a n:n relation with the users. To implement that I\'ve got
I also had trouble coming to grips with the fact that Dapper doesn't do this automatically.
First, I'm not sure about comma-separated values for "splitOn." I thought you could only have one value there. So I have multiple columns in my result set named "ID" for example.
Second, to get the proper 1:N relationships you need to do an extra manual step. For example, I did a 2-table join of participants and their phone numbers. Then I had to do this:
private List CollapseResultSet(List rawdataset)
{
List ret = new List();
if (!rawdataset.Any())
{
return ret;
}
else
{
List partIds = rawdataset.Select(p => p.ID).Distinct().ToList();
foreach (string pId in partIds)
{
Participant tmp = rawdataset.Where(p => p.ID == pId).FirstOrDefault();
tmp.PhoneNumbers = rawdataset.Where(p => p.ID == pId).Select(n => n.PhoneNumbers[0]).ToList();
ret.Add(tmp);
}
return ret;
}
}
Hope that helps.