Set Command Timeout in entity framework 4.3

前端 未结 3 1276
囚心锁ツ
囚心锁ツ 2020-12-05 17:28

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?

相关标签:
3条回答
  • 2020-12-05 18:01

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

    ((IObjectContextAdapter)context).ObjectContext.CommandTimeout = 180;
    
    0 讨论(0)
  • 2020-12-05 18:05

    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();
            }
    
    0 讨论(0)
  • 2020-12-05 18:17

    this command is enough.

    ((System.Data.Entity.Infrastructure.IObjectContextAdapter) context).ObjectContext.CommandTimeout
                    = 180;
    
    0 讨论(0)
提交回复
热议问题