© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago
AK sanTari

Dapper map to multiple Dictionaries

I'm using Dapper and .NET core 6 and am trying to map an object with multiple dictionaries in one sql query... is it possible?

The object looks like the following:
public class MasterDataModel
{
    public IEnumerable<KeyValuePair<int, string>>? Titles { get; set; }
    public IEnumerable<KeyValuePair<int, string>>? Genders { get; set; }
    public IEnumerable<KeyValuePair<int, string>>? Countries { get; set; }
}
public class MasterDataModel
{
    public IEnumerable<KeyValuePair<int, string>>? Titles { get; set; }
    public IEnumerable<KeyValuePair<int, string>>? Genders { get; set; }
    public IEnumerable<KeyValuePair<int, string>>? Countries { get; set; }
}


I can easily make multiple calls and map them (as follow) but was looking for something nicer.

var titles = await Task.FromResult(ExecuteQuery(q => q.Query<dynamic>("SELECT * FROM Mst.Title"))
    .ToDictionary(r => (int)r.TitleID, r => (string)r.TitleValue));

return new MasterDataModel() { Titles = titles };
var titles = await Task.FromResult(ExecuteQuery(q => q.Query<dynamic>("SELECT * FROM Mst.Title"))
    .ToDictionary(r => (int)r.TitleID, r => (string)r.TitleValue));

return new MasterDataModel() { Titles = titles };


Being using Slapper for other repo calls but can't find online anything for Dictionaries. Any idea?
Or can a stored procedure do that and Dapper detect and map the object?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Dapper
C#CC# / help
3y ago
Perform BulkInsert with multiple tables in dapper
C#CC# / help
3y ago
Dapper Migrations
C#CC# / help
17mo ago
Dapper problem
C#CC# / help
3y ago