For reference I'm using the Serenity application template.
I have the following code
var query = new SqlQuery();
query.From("TenantData")
.Select("ItemData")
.Select("ItemType")
.Where(new Criteria("TenantID") == userDefinition.TenantId);
using (var connection = sqlConnections.NewByKey("Default"))
{
var data = connection.Query(query);
}
The data returned looks like {{DapperRow, ItemData = '2342342wef', ItemType = 'test'}}
What I'm struggling with is how to convert this into a dictionary (ItemData being the key, ItemType being the value).
I've tried a select but it doesn't seem to be supported so I'm at a bit of a loss.
The following should work.
var data = connection.Query(query);
var d = data.ToDictionary(row => (string)row.itemdata, row => (string)row.itemtype);
Make sure you add the using System.Linq;
at the top. ToDictionary()
is an extension method.