Dapper not running Async together with Devart orac

2019-07-25 19:56发布

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.

0条回答
登录 后发表回答