none
EF 4.1 DbContext CommandTimeout?

    Question

  • How do you set the CommandTimeout for a EF4.1 Code First DbContext?

    Preemptively- Yes, this operation takes longer than 30 seconds to run.
    No, it's not an index issue.
    Yes, I _NEED_ all of the data at once.

    Wednesday, April 13, 2011 10:19 PM

Answers

  • Hello Storm, the command timeout needs to be set at the ObjectContext level. You can set it at least in the EF 4.1:

     

        using System.Data.Entity;
        using System.Data.Entity.Infrastructure;
    
        public class YourContext : DbContext
        {
          public YourContext()
            : base("YourConnectionString")
          {
            // Get the ObjectContext related to this DbContext
            var objectContext = (this as IObjectContextAdapter).ObjectContext;
    
            // Sets the command timeout for all the commands
            objectContext.CommandTimeout = 120;
          }
        }
    
    

    Hope this help you.

    Regards,

    Miguel.

     

    Friday, April 15, 2011 7:44 PM

All replies

  • Hello Storm, the command timeout needs to be set at the ObjectContext level. You can set it at least in the EF 4.1:

     

        using System.Data.Entity;
        using System.Data.Entity.Infrastructure;
    
        public class YourContext : DbContext
        {
          public YourContext()
            : base("YourConnectionString")
          {
            // Get the ObjectContext related to this DbContext
            var objectContext = (this as IObjectContextAdapter).ObjectContext;
    
            // Sets the command timeout for all the commands
            objectContext.CommandTimeout = 120;
          }
        }
    
    

    Hope this help you.

    Regards,

    Miguel.

     

    Friday, April 15, 2011 7:44 PM
  • That's what I was looking for, thanks.
    Friday, April 29, 2011 6:00 AM