我们可以在实体框架中动态设置命令TimeOut为“查询执行时间”吗?
发布于 2019-08-19 11:56:32
这条路:
using (var context = new EntityContext())
{
context.Database.CommandTimeout = 300;
}编辑:应答评论
基于CURD语句,我希望设置超时限制。
我不确定您使用的是哪个EF版本,因为您标记了EF6、EF5和EF4。
我将在我的回答中假设EF6
您可以使用DbCommandInterceptor:https://www.entityframeworktutorial.net/entityframework6/database-command-interception.aspx
检查CommandText并根据它设置CommandTimeout。
https://stackoverflow.com/questions/57521390
复制相似问题