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

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -