Search code examples
c#.net-coreasp.net-core-mvcdapper

How to Set Command Timeout in dapper globally


I have an ASP.NET Core 5 MVC project which uses Dapper. I have around 100 repositories in which Dapper is used. I want to set a command timeout now, one way is specifying individually on every Dapper query like this:

commandTimeout: TimeoutInSeconds

But that's very time consuming and not a good practice.

Is there anyway we can set command timeout globally in Dapper?


Solution

  • Just set it globally in dapper (just call it at the very beggining of your app):

    Dapper.SqlMapper.Settings.CommandTimeout = 100;