Tuesday, April 1, 2014

Function Evaluation Timed out error in Entity Framework

While running a time-consuming queries in Entity Framework, you may face the error saying "Function evaluation timed out".
In order to fix this error, you will need to increase the timeout of underlying DbContext.

Steps


  • Open "EntityName.Context.cs" file.
  • This file must be having an Entity class inherited from "DbContext"
  • Copy following code in the default constructor of this class:
            var adapter = (IObjectContextAdapter)this;
            var objectContext = adapter.ObjectContext;
            objectContext.CommandTimeout = 120; //2 minutes

Please note that CommandTimeout is in seconds.

No comments:

Post a Comment

Thanks for visiting my blog.
However, if this helped you in any way, please take a moment to write a comment.

Thanks
Nirman