How to set command timeout for entity objectcontext

587 views Asked by At

I have a repository file in which we have created object context of entity type and not of ObjectContext class type

public class ShopRepository : GenericRepository<tbl_Shop>
{
        // Entity Framework context to the database
        private DBEntities _contextObject;

        public ShopRepository(DBEntities context)
            : base(context)
        {
            this._contextObject = context;
        }
}

I need to set command timeout property. Can someone help me

1

There are 1 answers

0
CodeNotFound On BEST ANSWER

You can access to the DbContext command timeout through the CommandTimeout property of your ObjectContext like below:

((IObjectContextAdapter)context).ObjectContext.CommandTimeout

So if you want to set it in your ShopRepository ctor just do this:

public ShopRepository(DBEntities context)
        : base(context)
{
     ((IObjectContextAdapter)context).ObjectContext.CommandTimeout = your_value_here;
     this._contextObject = context;
}