5

way to map the following to a Dictionary??

Sql sql = new Sql()
.Append("SELECT Count(*) ")
.Append("FROM Custumers")
.Append("WHERE CustomerId = @0", Id)

var result = database.Fetch<Dictionary<int,DateTime>>(sql);

I cannot use List as DateTime is also thr.

Aakansha
  • 559
  • 2
  • 7
  • 21

2 Answers2

7

Petapoco always return a List<T>, but you can convert the List to a Dictionary afterwards:

var result = database
    .Fetch<Pair<int,DateTime>>(sql)
    .ToDictionary(i => i.ID, i => i.Date);
Eduardo Molteni
  • 38,786
  • 23
  • 141
  • 206
  • 5
    What is Pair in this case? KeyValuePair does not work – Daniel Williams Sep 23 '17 at 17:26
  • 1
    For anyone else that is reading this and is wondering what a Pair is, it looks like it's a generic class that was inspired by the answer at https://stackoverflow.com/a/13646110/3830432 – Doug F Feb 23 '22 at 19:51
6

With NPoco you can write this: it will use the first 2 columns

var result = database.Dictionary<int, DateTime>(sql);

or use what @Eduardo said.

Schotime
  • 15,707
  • 10
  • 46
  • 75