Dapper not running Async together with Devart oracle driver

时光毁灭记忆、已成空白 提交于 2019-12-24 07:36:03

问题


I have a repository method in a ASP WebApi site

    public async Task<IEnumerable<Animal>> GetAnimals(List<long> herdIds)
    {
        using (var sqlConnection = new OracleConnection(Connectionstring))
        {
            await sqlConnection.OpenAsync();

            var sql = GetCommonSqlQuery(herdIds, true);

            var result = await sqlConnection.QueryAsync<Prop1, Prop2, Prop3, Prop1>(
                sql,
                (a, g, b) =>
                {
                    a.Prop2 = g;
                    a.Prop3= b;
                    return a;
                });

            return result;
        }
    }

I use that with

Task<IEnumerable<Animal>> animalsTask = animalsRepository.GetAnimals(herdIds);
Task<List<AnalysisAnimalTest>> testsTask =analysisId.HasValue ? GetAnalysisAnimalTests(analysisId.Value, herdIds) : null;

await Task.WhenAll(new List<Task> {testsTask, animalsTask}.Where(t => t != null));

But if I debug and step over this code, then it stops and executes

Task<IEnumerable<Animal>> animalsTask = animalsRepository.GetAnimals(herdIds);

I want both tasks to run in parallel and therefore it should not stop and finish executing before I await in

await Task.WhenAll(new List<Task> {testsTask, animalsTask}.Where(t => t != null));

Am I misunderstanding some basic Await / Async stuff or using the dapper framework wrong?

It might also be my OpenAsync with the Devart Oracle driver, but not entirely sure, when reading "open/close" SqlConnection or keep open? it seems that I should open and close in every repository method.

来源:https://stackoverflow.com/questions/42979094/dapper-not-running-async-together-with-devart-oracle-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!