Пример #1
0
        public SmartSqlBuilder UseDataSource(String dbProviderName, String connectionString)
        {
            if (string.IsNullOrEmpty(dbProviderName))
            {
                throw new ArgumentNullException(nameof(dbProviderName));
            }

            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            if (!DbProviderManager.Instance.TryGet(dbProviderName, out var dbProvider))
            {
                throw new SmartSqlException($"can not find {dbProviderName}.");
            }

            WriteDataSource writeDataSource = new WriteDataSource
            {
                Name             = "Write",
                ConnectionString = connectionString,
                DbProvider       = dbProvider
            };

            return(UseDataSource(writeDataSource));
        }
Пример #2
0
        public IDbSession Open(string connectionString)
        {
            var dataSource = new WriteDataSource
            {
                Name             = "Write",
                ConnectionString = connectionString,
                DbProvider       = SmartSqlConfig.Database.DbProvider
            };

            return(Open(dataSource));
        }
Пример #3
0
        /// <summary>
        /// 数据源方式构建
        /// </summary>
        /// <param name="writeDataSource"></param>
        /// <returns></returns>
        public SmartSqlBuilder UseDataSource(WriteDataSource writeDataSource)
        {
            if (writeDataSource == null)
            {
                throw new ArgumentNullException(nameof(writeDataSource));
            }
            var smartSqlConfig = new SmartSqlConfig
            {
                Database = new Database
                {
                    DbProvider = writeDataSource.DbProvider,
                    Write      = writeDataSource
                }
            };

            return(UseNativeConfig(smartSqlConfig));
        }
Пример #4
0
        private WriteDataSource ParseWriteDataSource(XmlNode writeDataSourceNode)
        {
            if (writeDataSourceNode == null)
            {
                throw new SmartSqlException("WriteDataSource can not be null.");
            }
            var writeDataSource = new WriteDataSource();

            if (writeDataSourceNode.Attributes.TryGetValueAsString(nameof(WriteDataSource.Name), out string name, SmartSqlConfig.Properties)
                )
            {
                writeDataSource.Name = name;
            }
            if (writeDataSourceNode.Attributes.TryGetValueAsString(nameof(WriteDataSource.ConnectionString), out string connectionString, SmartSqlConfig.Properties)
                )
            {
                writeDataSource.ConnectionString = connectionString;
            }

            return(writeDataSource);
        }