I was trying to keep from having to create a model just for this. I just need to get a Dictionary<int,string>
from a stored procedure but it doesn’t look like cmd.ConvertTo<Dictionary<int, string>>()
works. I get an empty Dictionary
with the following proc…
use Testing
go
create procedure dbo.SelectTestDictionary
as
begin
set nocount on;
-- Select back results as a dictionary of <ID,Action>
select 1 as 'ID', 'ADD' as 'Action'
union all
select 2 as 'ID', 'REMOVE' as 'Action'
end
using the following test…
public void SelectDictionaryFromProc()
{
using (var db = _DBFactory.OpenDbConnection())
{
using (var cmd = db.SqlProc("dbo.SelectTestDictionary"))
{
var result = cmd.ConvertTo<Dictionary<int, string>>();
if (result != null && result.Any())
result.PrintDump();
else
Console.WriteLine("result is empty");
}
}
}
What am I missing here to do this without having to create a model and use cmd.ConvertToList<IDWithActionModel>();
?