Exemple #1
0
        private static DbContext Initialize()
        {
            var builder = new DbContext.Builder();

            builder.Services.AddService <IParameterizedQueryBuilder>(provider => new ParameterizedQueryBuilder());
            builder.Services.AddService <ITemplateParser, TemplateParser>();

            return(builder.Build());
        }
Exemple #2
0
        /// <summary>
        /// 通过集成身份验证登陆 MySql 数据库,以创建 MySql 数据库访问器
        /// </summary>
        /// <param name="server">数据库服务器实例名称</param>
        /// <param name="database">数据库名称</param>
        /// <param name="pooling">是否启用连接池(默认启用)</param>
        /// <param name="configuration">MySql 数据库配置</param>
        /// <returns>MySql 数据库访问器</returns>
        public static DbContext.Builder UseMySql(this DbContext.Builder builder, string server, string database, bool pooling = true)
        {
            var connectionBuilder = new MySqlConnectionStringBuilder()
            {
                Server   = server,
                Database = database,
                Pooling  = pooling
            };

            return(UseMySql(builder, connectionBuilder.ConnectionString));
        }
Exemple #3
0
        /// <summary>
        /// 通过集成身份验证登陆 SQL Server 数据库,以创建 SQL Server 数据库访问器
        /// </summary>
        /// <param name="builder">数据库访问上下文构建器</param>
        /// <param name="dataSource">数据库服务器实例名称</param>
        /// <param name="initialCatalog">数据库名称</param>
        /// <param name="pooling">是否启用连接池(默认启用)</param>
        /// <returns>SQL Server 数据库访问器</returns>
        public static DbContext.Builder UseSqlServer(this DbContext.Builder builder, string dataSource, string initialCatalog, bool pooling = true)
        {
            var connectionBuilder = new SqlConnectionStringBuilder()
            {
                DataSource         = dataSource,
                InitialCatalog     = initialCatalog,
                IntegratedSecurity = true,
                Pooling            = pooling
            };

            return(UseSqlServer(builder, connectionBuilder.ConnectionString));
        }
Exemple #4
0
        /// <summary>
        /// 通过指定的用户名和密码登陆 MySql 数据库,以创建 MySql 数据库访问器
        /// </summary>
        /// <param name="server">数据库服务器地址</param>
        /// <param name="port">数据库服务器端口</param>
        /// <param name="database">数据库名称</param>
        /// <param name="userID">登录数据库的用户名</param>
        /// <param name="password">登录数据库的密码</param>
        /// <param name="pooling">是否启用连接池(默认启用)</param>
        /// <param name="configuration">MySql 数据库配置</param>
        /// <returns>MySql 数据库访问器</returns>
        public static DbContext.Builder UseMySql(this DbContext.Builder builder, string server, uint port, string database, string userID, string password, bool pooling = true)
        {
            var connectionBuilder = new MySqlConnectionStringBuilder()
            {
                Server   = server,
                Database = database,
                UserID   = userID,
                Password = password,
                Pooling  = pooling
            };

            return(UseMySql(builder, connectionBuilder.ConnectionString));
        }
Exemple #5
0
        /// <summary>
        /// 通过指定的连接字符串并创建 SQL Server 数据库访问器
        /// </summary>
        /// <param name="builder">数据库访问上下文构建器</param>
        /// <param name="connectionString">连接字符串</param>
        /// <returns>SQL Server 数据库访问器</returns>
        public static DbContext.Builder UseSqlServer(this DbContext.Builder builder, string connectionString)
        {
            builder.SetDbProvider(new SqlServerDbProvider(connectionString));

            return(builder);
        }
Exemple #6
0
 /// <summary>
 /// 通过指定的连接字符串构建器创建 MySql 数据库访问器
 /// </summary>
 /// <param name="builder">连接字符串构建器</param>
 /// <param name="configuration">MySql 配置</param>
 /// <returns>MySql 数据库访问器</returns>
 public static DbContext.Builder UseMySql(this DbContext.Builder builder, MySqlConnectionStringBuilder connectionBuilder)
 {
     return(UseMySql(builder, connectionBuilder.ConnectionString));
 }