0
ashgadala created
This might not be directly related to ASPNETZERO problem. I appreciate if some one can help.
Support, I got the result that i am expecting with below implementation. Is this the best way to handle it Or Do you recommend a better way ? Appreciate any help.
I was able to successfully implement the GetUserNames() task by following the documentation.
I modified the store procedure to include all columns in the UserlistDTO and would like to return all the columns.
Implementation from documentation
public async Task<List<string>> GetUserNames()
{
EnsureConnectionOpen();
using (var command = CreateCommand("GetUsernames", CommandType.storedProcedure))
{
using (var dataReader = await command.ExecuteReaderAsync())
{
var result = new List<string>();
while (dataReader.Read())
{
result.Add(dataReader["UserName"].ToString());
}
return result;
}
}
}
My Implementation based on Stackoverflow thread
This stackoverflow Thread case to rescue.
Here is the my UserRepository.
public async Task<IEnumerable<object>> GetUserNamesarray()
{
using (var command = CreateCommand("GetUsernames", CommandType.StoredProcedure))
{
using (var dataReader = await command.ExecuteReaderAsync())
{
var retObject = new List<dynamic>();
while (await dataReader.ReadAsync())
{
var dataRow = new ExpandoObject() as IDictionary<string, object>;
for (var iFiled = 0; iFiled < dataReader.FieldCount; iFiled++)
{
dataRow.Add(
dataReader.GetName(iFiled),
dataReader.IsDBNull(iFiled) ? null : dataReader[iFiled] // use null instead of {}
);
}
retObject.Add((ExpandoObject)dataRow);
}
return retObject;
}
}
}