C# 在实体框架 4.3 中设置命令超时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11747368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set Command Timeout in entity framework 4.3
提问by Saher Ahwal
I cannot find the a way to set the command timeout of a linq query using entity framework 4.3 and its' DbContext. How do I increase Commandtimeout in entity framework?
我找不到使用实体框架 4.3 及其 DbContext 设置 linq 查询的命令超时的方法。如何在实体框架中增加 Commandtimeout?
EDITI am actually looking for Command Timeout increase. I confused the two, it is the sql command that is timing out not the connection.
编辑我实际上正在寻找命令超时增加。我混淆了两者,是 sql 命令超时而不是连接。
Thanks
谢谢
采纳答案by bricelam
If you're using DbContext, you'll first need to drop down to ObjectContext:
如果您正在使用 DbContext,您首先需要下拉到 ObjectContext:
((IObjectContextAdapter)context).ObjectContext.CommandTimeout = 180;
回答by m-Abrontan
this command is enough.
这个命令就够了。
((System.Data.Entity.Infrastructure.IObjectContextAdapter) context).ObjectContext.CommandTimeout
= 180;
回答by Maurice Jordan
I added the command timeout value in my Context class in an attempt to handle longer processing times for some of the stored procedures that are populating my application. Seems to have done the trick.
我在我的 Context 类中添加了命令超时值,以尝试处理填充我的应用程序的某些存储过程的更长处理时间。似乎已经成功了。
public partial class ExampleEntities : DbContext
{
public ExampleEntities()
: base("name=ExampleEntities")
{
((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 180;
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}

