예제 #1
0
        public HistoryRepository(
            InternalContext usersContext,
            string connectionString,
            DbProviderFactory providerFactory,
            string contextKey,
            int?commandTimeout,
            Func <DbConnection, string, HistoryContext> historyContextFactory,
            IEnumerable <string> schemas            = null,
            DbContext contextForInterception        = null,
            DatabaseExistenceState initialExistence = DatabaseExistenceState.Unknown)
            : base(usersContext, connectionString, providerFactory)
        {
            this._initialExistence    = initialExistence;
            this._commandTimeout      = commandTimeout;
            this._existingTransaction = usersContext.TryGetCurrentStoreTransaction();
            this._schemas             = ((IEnumerable <string>) new string[1]
            {
                "dbo"
            }).Concat <string>(schemas ?? Enumerable.Empty <string>()).Distinct <string>();
            this._contextForInterception = contextForInterception;
            this._historyContextFactory  = historyContextFactory;
            DbConnection connection = (DbConnection)null;

            try
            {
                connection = this.CreateConnection();
                using (HistoryContext context = this.CreateContext(connection, (string)null))
                {
                    EntityType entityType = ((IObjectContextAdapter)context).ObjectContext.MetadataWorkspace.GetItems <EntityType>(DataSpace.CSpace).Single <EntityType>((Func <EntityType, bool>)(et => EntityTypeExtensions.GetClrType(et) == typeof(HistoryRow)));
                    int?       maxLength  = entityType.Properties.Single <EdmProperty>((Func <EdmProperty, bool>)(p => p.GetClrPropertyInfo().IsSameAs(HistoryRepository.MigrationIdProperty))).MaxLength;
                    this._migrationIdMaxLength = maxLength.HasValue ? maxLength.Value : 150;
                    maxLength = entityType.Properties.Single <EdmProperty>((Func <EdmProperty, bool>)(p => p.GetClrPropertyInfo().IsSameAs(HistoryRepository.ContextKeyProperty))).MaxLength;
                    this._contextKeyMaxLength = maxLength.HasValue ? maxLength.Value : 300;
                }
            }
            finally
            {
                this.DisposeConnection(connection);
            }
            this._contextKey = contextKey.RestrictTo(this._contextKeyMaxLength);
        }
예제 #2
0
        public HistoryRepository(
            InternalContext usersContext,
            string connectionString,
            DbProviderFactory providerFactory,
            string contextKey,
            int?commandTimeout,
            Func <DbConnection, string, HistoryContext> historyContextFactory,
            IEnumerable <string> schemas            = null,
            DbContext contextForInterception        = null,
            DatabaseExistenceState initialExistence = DatabaseExistenceState.Unknown)
            : base(usersContext, connectionString, providerFactory)
        {
            DebugCheck.NotEmpty(contextKey);
            DebugCheck.NotNull(historyContextFactory);

            _initialExistence    = initialExistence;
            _commandTimeout      = commandTimeout;
            _existingTransaction = usersContext.TryGetCurrentStoreTransaction();

            _schemas
                = new[] { EdmModelExtensions.DefaultSchema }
            .Concat(schemas ?? Enumerable.Empty <string>())
            .Distinct();

            _contextForInterception = contextForInterception;
            _historyContextFactory  = historyContextFactory;
            DbConnection connection = null;

            try
            {
                connection = CreateConnection();

                using (var context = CreateContext(connection))
                {
                    var historyRowEntity
                        = ((IObjectContextAdapter)context).ObjectContext
                          .MetadataWorkspace
                          .GetItems <EntityType>(DataSpace.CSpace)
                          .Single(et => et.GetClrType() == typeof(HistoryRow));

                    var maxLength
                        = historyRowEntity
                          .Properties
                          .Single(p => p.GetClrPropertyInfo().IsSameAs(MigrationIdProperty))
                          .MaxLength;

                    _migrationIdMaxLength
                        = maxLength.HasValue
                            ? maxLength.Value
                            : HistoryContext.MigrationIdMaxLength;

                    maxLength
                        = historyRowEntity
                          .Properties
                          .Single(p => p.GetClrPropertyInfo().IsSameAs(ContextKeyProperty))
                          .MaxLength;

                    _contextKeyMaxLength
                        = maxLength.HasValue
                            ? maxLength.Value
                            : HistoryContext.ContextKeyMaxLength;
                }
            }
            finally
            {
                DisposeConnection(connection);
            }

            _contextKey = contextKey.RestrictTo(_contextKeyMaxLength);
        }
예제 #3
0
        public HistoryRepository(
            InternalContext usersContext,
            string connectionString,
            DbProviderFactory providerFactory,
            string contextKey,
            int? commandTimeout,
            Func<DbConnection, string, HistoryContext> historyContextFactory,
            IEnumerable<string> schemas = null,
            DbContext contextForInterception = null,
            DatabaseExistenceState initialExistence = DatabaseExistenceState.Unknown)
            : base(usersContext, connectionString, providerFactory)
        {
            DebugCheck.NotEmpty(contextKey);
            DebugCheck.NotNull(historyContextFactory);

            _initialExistence = initialExistence;
            _commandTimeout = commandTimeout;
            _existingTransaction = usersContext.TryGetCurrentStoreTransaction();

            _schemas
                = new[] { EdmModelExtensions.DefaultSchema }
                    .Concat(schemas ?? Enumerable.Empty<string>())
                    .Distinct();

            _contextForInterception = contextForInterception;
            _historyContextFactory = historyContextFactory;
            DbConnection connection = null;
            try
            {
                connection = CreateConnection();

                using (var context = CreateContext(connection))
                {
                    var historyRowEntity
                        = ((IObjectContextAdapter)context).ObjectContext
                            .MetadataWorkspace
                            .GetItems<EntityType>(DataSpace.CSpace)
                            .Single(et => et.GetClrType() == typeof(HistoryRow));

                    var maxLength
                        = historyRowEntity
                            .Properties
                            .Single(p => p.GetClrPropertyInfo().IsSameAs(MigrationIdProperty))
                            .MaxLength;

                    _migrationIdMaxLength
                        = maxLength.HasValue
                            ? maxLength.Value
                            : HistoryContext.MigrationIdMaxLength;

                    maxLength
                        = historyRowEntity
                            .Properties
                            .Single(p => p.GetClrPropertyInfo().IsSameAs(ContextKeyProperty))
                            .MaxLength;

                    _contextKeyMaxLength
                        = maxLength.HasValue
                            ? maxLength.Value
                            : HistoryContext.ContextKeyMaxLength;
                }
            }
            finally
            {
                DisposeConnection(connection);
            }

            _contextKey = contextKey.RestrictTo(_contextKeyMaxLength);
        }
 public EdmMetadataRepository(InternalContext usersContext, string connectionString, DbProviderFactory providerFactory)
     : base(usersContext, connectionString, providerFactory)
 {
     _existingTransaction = usersContext.TryGetCurrentStoreTransaction();
 }