Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Execute Sql Async with ToList

$
0
0
protected virtual async Task<IEnumerable<T>> ExecuteAPI_SQLQuery_ObjectListAsync<T>(DB_ID db_id, string sqlQuery, object queryParameters){
try
{
string dbString = GetDBStringAsync(db_id);
using (DbConnection conn = new SqlConnection(dbString))
{
List<T> tResults = null;
tResults = await Task.FromResult((conn.QuerySqlAsync<T>(sqlQuery, queryParameters)).Result.ToList());

return tResults;
}
}
catch (Exception e)
{
}



After much searching the internet and trial and error I now have the above code compiling but it still seems to run synchronously.  This uses insight.Database orm where querysqlasync is supported so I feel it is the use of Task.FromResult or Result.ToList may be waht is causing the issue.

I have ensured I am using a SQLConnection with Allow Asynchronous = true.  But feel the problem lies with the above code despite it compiling.  The issue I had and what lead me to construct it in the above way was around converting IList to Generic List.

Does anyone have any ideas for an alternative working solution?


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>