Command Timeout with Entity Framework 4.1 Code First

后端 未结 5 1205
攒了一身酷
攒了一身酷 2021-01-01 10:06

How can I set the command timeout of a DbContext?

5条回答
  •  一整个雨季
    2021-01-01 10:23

    I found this solution after another Google search. You can access the ObjectContext for a DbContext by casting this to an IObjectContextAdapter.

    From http://social.msdn.microsoft.com/Forums/en-ZA/adodotnetentityframework/thread/6fe91a64-0208-4ab8-8667-d061af340994:

    public class MyContext : DbContext
    {
        public MyContext ()
            : base(ContextHelper.CreateConnection("my connection string"), true)
        {
            ((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 300;
        }
    }
    

提交回复
热议问题