Command Timeout with Entity Framework 4.1 Code First

后端 未结 5 1241
攒了一身酷
攒了一身酷 2021-01-01 10:06

How can I set the command timeout of a DbContext?

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-01 10:29

    Please try the following code before you execute any DB command. The following Code need 3/4 minute to execute. So, CommandTimeout set 300 (in seconds) before execution of the command.

    public List ReadCollectionEfficiencyByUnitOfficeSummary(string yearMonth, string locationCode, string reportType)
            {
                ((System.Data.Entity.Infrastructure.IObjectContextAdapter)context).ObjectContext.CommandTimeout = 300;
                return context.CollectionEfficiencyByUnitOfficeSummary(yearMonth, locationCode, reportType).ToList();
            }
    

提交回复
热议问题