How to set command timeout in aspnetcore/entityframeworkcore

后端 未结 3 1710
长情又很酷
长情又很酷 2021-02-06 21:28

The place where the command timeout is set is no longer the same as earlier versions.

However, I cannot find anywhere that says how to change this.

What I am doi

3条回答
  •  轮回少年
    2021-02-06 21:46

    The better option is to use CommandTimeout during your context setup like:

    public class DbConnect: IConnnectDb
    {
        private dbentitient _context;
    
        // inject this to a db entity from constructor. 
    
        //inside each method now use the follow before u actually run the query to db.  
    
        _context.Database.SetCommandTimeout(400);
    }     
    

    Note: EF Core will only execute the query with less than 100 seconds time. If it's more than that it keeps retrying and you never get to see the result.

    That's my experience as of now, so let me know if you are able to fix it EF Core 1.0 does timeout even more fast than EF Core 2.0.

提交回复
热议问题