Base solution for your next web application
Open Closed

IDapperRepository not using UOW Timeout property #8403


User avatar
0
rbarbosa created

Hello

We have a few queries that run reports, naturally these take longer than the default 30 seconds when the user. I have tried wrapping the query in a using statement or using the UOW attribute, but when the query times out, the SqlConnection does not show the overriden value

Any ideas on how to set this up?

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    hi

    Try TransactionScopeOption.RequiresNew

    using (var uow = _unitOfWorkManager.Begin(new UnitOfWorkOptions
    {
    	Scope = TransactionScopeOption.RequiresNew,
    	IsTransactional = false,
    	Timeout = new TimeSpan(0,5,0)
    }))
    
    
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    rbarbosa created

    Hi, thanks for your help, sadly this did not help, looking at the source : https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.Dapper/Dapper/Repositories/DapperRepositoryBaseOfTEntityAndTPrimaryKey.cs#L102 it seems that dapper retrieves the command timeout from a parameter, which is not being passed

    https://github.com/StackExchange/Dapper/blob/master/Dapper/SqlMapper.cs#L647

    What i did was override DapperRepositoryBase, inject UOWManager and get the data from there

    private int? CommandTimeout =>
                _unitOfWorkManager.Current?.Options.Timeout != null
                    ? (int?) Convert.ToInt32(_unitOfWorkManager.Current.Options.Timeout?.TotalSeconds)
                    : null;
    
    public override Task<IEnumerable<TAny>> QueryAsync<TAny>(string query, object parameters = null)
            {
                return Connection.QueryAsync<TAny>(query, parameters, ActiveTransaction, commandTimeout: CommandTimeout);
            }
    

    I am unsure if this is the right path but it seems to get the data where it needs to be either via attribute or with a using statement, gets a bit confusing as the attribute takes the time as INT Milliseconds, the UnitOfWorkOptions take the time as a TimeSpan, which convert to double seconds, and Dapper takes the time as Int seconds

    [UnitOfWork(isTransactional: false, timeout: TIME_IN_MS)]
    

    Eitherways it seems to solve my issue, but I am open on seeing a better way on doing this. Thanks

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    ismcagdas created
    Support Team

    @rbarbosa

    Could you create an issue on https://github.com/aspnetboilerplate/aspnetboilerplate so we can enhance it ?

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)