/// <summary>
        /// Creates a new <see cref="DataContext"/> using connection string settings from ConfigurationManager.
        /// </summary>
        protected virtual DataContext CreateDbDataContext(string aggregateRootTypeName = null)
        {
            string connectionStringKey;
            string applicationKey;

            if (!ConfigurationManager.TryGetSetting(SqlSnapshotStoreConnectionNameApplicationKey, out applicationKey) || string.IsNullOrEmpty(applicationKey))
            {
                throw new MissingApplicationSettingForConnectionStringException(SqlSnapshotStoreConnectionNameApplicationKey);
            }
            ConnectionStringSettings connectionString = System.Configuration.ConfigurationManager.ConnectionStrings[applicationKey];

            if (connectionString == null)
            {
                throw new MissingConnectionStringException(applicationKey);
            }
            connectionStringKey = connectionString.ConnectionString;

            string tableName;

            if (!string.IsNullOrWhiteSpace(aggregateRootTypeName) && ConfigurationManager.TryGetSetting(string.Format(SqlSnapshotStoreTableNameApplicationKeyPattern, aggregateRootTypeName), out tableName) && !string.IsNullOrEmpty(tableName))
            {
                bool autoname;
                if (bool.TryParse(tableName, out autoname))
                {
                    if (autoname)
                    {
                        return(LinqToSqlEventStoreDataContext.New <EventData>(aggregateRootTypeName.Replace(".", "_"), connectionStringKey));
                    }
                }
                else
                {
                    return(LinqToSqlEventStoreDataContext.New <EventData>(tableName, connectionStringKey));
                }
            }

            return(LinqToSqlEventStoreDataContext.New <EventData>("Snapshots", connectionStringKey));
        }
示例#2
0
        /// <summary>
        /// Creates a new <see cref="DataContext"/> using connection string settings from <see cref="ConfigurationManager"/>.
        /// </summary>
        protected virtual DataContext CreateDbDataContext(string aggregateRootTypeName = null)
        {
            string connectionStringKey = ConfigurationManager.GetConnectionStringBySettingKey(SqlEventStoreConnectionNameApplicationKey, true, true);

            string tableName;

            if (!string.IsNullOrWhiteSpace(aggregateRootTypeName) && ConfigurationManager.TryGetSetting(string.Format(SqlEventStoreTableNameApplicationKeyPattern, aggregateRootTypeName), out tableName) && !string.IsNullOrEmpty(tableName))
            {
                bool autoname;
                if (bool.TryParse(tableName, out autoname))
                {
                    if (autoname)
                    {
                        return(LinqToSqlEventStoreDataContext.New <EventData>(aggregateRootTypeName.Replace(".", "_"), connectionStringKey));
                    }
                    else
                    {
                        return(LinqToSqlEventStoreDataContext.New <EventData>(tableName, connectionStringKey));
                    }
                }
            }

            return(new LinqToSqlEventStoreDataContext(connectionStringKey));
        }