c# - Best way to read IDataReader for WebApi -


i have webapi action returns dynamic result based on sql query. using following function convert idatareader works fine, creates dictionary object each row. wondering if there better way that.

private ienumerable readresult(idatareader reader) {     var names = new string[reader.fieldcount];     var values = new object[reader.fieldcount];      (var = 0; < reader.fieldcount; i++)     {         names[i] = reader.getname(i);     }      while (reader.read())     {         reader.getvalues(values);          var record = names.todictionary(i => i, s => values[array.indexof(names, s)]);          yield return record;     } } 

you can try approach (don't know how play webapi, still worth try):

var record = new expandoobject() idictionary<string, object>; foreach(var name in names)     record[name] = values[array.indexof(names, name)];  yield return record; 

Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -