Exemplo n.º 1
0
        public static IDisposable Use(DbContextCreationContext context)
        {
            var previousValue = Current;

            _current.Value = context;
            return(new DisposeAction(() => _current.Value = previousValue));
        }
Exemplo n.º 2
0
        private TDbContext CreateDbContext(IUnitOfWork unitOfWork, string connectionStringName, string connectionString)
        {
            var creationContext = new DbContextCreationContext(connectionStringName, connectionString);

            using (DbContextCreationContext.Use(creationContext))
            {
                var dbContext = CreateDbContext(unitOfWork);

                if (unitOfWork.Options.Timeout.HasValue &&
                    dbContext.Database.IsRelational() &&
                    !dbContext.Database.GetCommandTimeout().HasValue)
                {
                    dbContext.Database.SetCommandTimeout(unitOfWork.Options.Timeout.Value.TotalSeconds.To <int>());
                }

                return(dbContext);
            }
        }