Skip to content

Instantly share code, notes, and snippets.

@AlexArchive
Created February 5, 2015 20:17
Show Gist options
  • Save AlexArchive/258149b64ced1527a55b to your computer and use it in GitHub Desktop.
Save AlexArchive/258149b64ced1527a55b to your computer and use it in GitHub Desktop.
var lookup = new Dictionary<int, Artist>();
IEnumerable<Artist> foo =
connection.Query<Artist, Record, Artist>(
"SELECT * FROM dbo.Artists INNER JOIN dbo.Records ON dbo.Records.artistId = dbo.Artists.id",
(a, r) =>
{
Artist artist;
if (!lookup.TryGetValue(a.Id, out artist))
{
lookup.Add(a.Id, artist = a);
}
if (artist.Records == null)
{
artist.Records = new List<Record>();
}
artist.Records.Add(r);
return artist;
});
var result = lookup.Values;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment