/// <summary> /// Constructor /// </summary> public UnitOfWork(MvcForumContext context) { _context = context; // In order to make calls that are overidden in the caching ef-wrapper, we need to use // transactions from the connection, rather than TransactionScope. // This results in our call e.g. to commit() being intercepted // by the wrapper so the cache can be adjusted. // This won't work with the dbcontext because it handles the connection itself, so we must use the underlying ObjectContext. // http://blogs.msdn.com/b/diego/archive/2012/01/26/exception-from-dbcontext-api-entityconnection-can-only-be-constructed-with-a-closed-dbconnection.aspx _objectContext = ((IObjectContextAdapter)_context).ObjectContext; // Updating EF timeout taken from // http://stackoverflow.com/questions/6232633/entity-framework-timeouts //_objectContext.CommandTimeout = 3 * 60; // value in seconds if (_objectContext.Connection.State != ConnectionState.Open) { _objectContext.Connection.Open(); _transaction = _objectContext.Connection.BeginTransaction(); } }
public UnitOfWorkManager(IMvcForumContext context) { //http://www.entityframeworktutorial.net/code-first/automated-migration-in-code-first.aspx Database.SetInitializer(new MigrateDatabaseToLatestVersion <MvcForumContext, Configuration>(SiteConstants.Instance.MvcForumContext)); _context = context as MvcForumContext; }