/// <summary> /// Builds an <see cref="InPlaceConfigurationSource"/> for the specified database. /// </summary> /// <param name="database">The database type.</param> /// <param name="connectionString">The connection string.</param> /// <returns></returns> public static InPlaceConfigurationSource Build(DatabaseType database, string connectionString) { if (string.IsNullOrEmpty(connectionString)) { throw new ArgumentNullException("connectionString"); } var config = new InPlaceConfigurationSource(); var parameters = new DefaultDatabaseConfiguration().For(database); parameters["connection.connection_string"] = connectionString; config.Add(typeof(ActiveRecordBase), parameters); return(config); }
/// <summary> /// Sets the default configuration for database specifiend by <paramref name="name"/>. /// </summary> /// <param name="name">Name of the database type.</param> /// <param name="connectionStringName">name of the connection string specified in connectionStrings configuration section</param> /// <returns></returns> protected IDictionary <string, string> SetDefaults(string name, string connectionStringName) { var names = Enum.GetNames(typeof(DatabaseType)); if (!Array.Exists(names, n => n.Equals(name, StringComparison.OrdinalIgnoreCase))) { var builder = new StringBuilder(); builder.AppendFormat("Specified value ({0}) is not valid for 'database' attribute. Valid values are:", name); foreach (var value in Enum.GetValues(typeof(DatabaseType))) { builder.AppendFormat(" '{0}'", value.ToString()); } builder.Append("."); throw new ConfigurationErrorsException(builder.ToString()); } var type = (DatabaseType)Enum.Parse(typeof(DatabaseType), name, true); var defaults = new DefaultDatabaseConfiguration().For(type); defaults["connection.connection_string_name"] = connectionStringName; return(defaults); }