Set Command Timeout in entity framework 4.3

2019-01-14 10:35发布

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?

EDIT I am actually looking for Command Timeout increase. I confused the two, it is the sql command that is timing out not the connection.

Thanks

3条回答
迷人小祖宗
2楼-- · 2019-01-14 11:08

this command is enough.

((System.Data.Entity.Infrastructure.IObjectContextAdapter) context).ObjectContext.CommandTimeout
                = 180;
查看更多
虎瘦雄心在
3楼-- · 2019-01-14 11:18

If you're using DbContext, you'll first need to drop down to ObjectContext:

((IObjectContextAdapter)context).ObjectContext.CommandTimeout = 180;
查看更多
淡お忘
4楼-- · 2019-01-14 11:27

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.

public partial class ExampleEntities : DbContext
    {
        public ExampleEntities()
            : base("name=ExampleEntities")
        {
            ((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 180;
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }
查看更多
登录 后发表回答