Exemple #1
0
        private static string GetConnectionString(DbProviderElement element)
        {
            String connStr = null;

            if (String.IsNullOrEmpty(element.ConnectionStringName))
            {
                connStr = element.ConnectionString;
            }
            else
            {
                ConnectionStringSettings css = ConfigurationManager.ConnectionStrings[element.ConnectionStringName];
                if (css != null)
                {
                    connStr = css.ConnectionString;
                }
            }
            return(connStr);
        }
Exemple #2
0
        /// <summary>
        /// Initializes EasyDbHelper.
        /// </summary>
        /// <param name="config">the <see cref="LX.EasyDb.Configuration.EasyDbConfiguration"/></param>
        public static void Initialize(EasyDbConfiguration config)
        {
            if (config != null && config.Providers.Count > 0)
            {
                IConnectionFactory        masterProvider = null;
                List <IConnectionFactory> slaveProviders = new List <IConnectionFactory>();

                DbProviderElement primaryProviderElement = config.MasterProvider;
                if (null == primaryProviderElement)
                {
                    throw new ConfigurationErrorsException("Master provider is not found.");
                }
                masterProvider = CreateConnectionFactory(primaryProviderElement);
                if (masterProvider == null)
                {
                    throw new ConfigurationErrorsException("Unable to load " + primaryProviderElement.Name);
                }

                // TODO slave mode
                ConnectionFactory = masterProvider;
            }
        }
Exemple #3
0
 private static IConnectionFactory CreateConnectionFactory(DbProviderElement element)
 {
     return(ConnectionFactoryBuilder.NewBuilder(element.Provider, GetConnectionString(element), element.Name, element.Dialect).Build());
 }