Beispiel #1
0
        /// <summary>
        /// 创建数据库适配器
        /// </summary>
        /// <param name="databaseFacade">ADO.NET 数据库对象</param>
        /// <param name="sql">sql 语句</param>
        /// <param name="commandType">命令类型</param>
        /// <returns>(DbConnection dbConnection, DbCommand dbCommand, DbDataAdapter dbDataAdapter)</returns>
        private static (DbConnection dbConnection, DbCommand dbCommand, DbDataAdapter dbDataAdapter) CreateDbDataAdapter(this DatabaseFacade databaseFacade, string sql, CommandType commandType = CommandType.Text)
        {
            // 检查是否支持存储过程
            DbProvider.CheckStoredProcedureSupported(databaseFacade.ProviderName, commandType);

            // 获取数据库连接字符串
            var dbConnection = databaseFacade.GetDbConnection();

            // 解析数据库提供器
            var dbProviderFactory = DbProviderFactories.GetFactory(dbConnection);

            // 判断是否启用 MiniProfiler 组件,如果有,则包装链接和数据库提供器工厂
            var profiledDbProviderFactory = InjectMiniProfiler ? new ProfiledDbProviderFactory(dbProviderFactory, true) : dbProviderFactory;

            // 创建数据库连接对象及数据库命令对象
            var(_dbConnection, dbCommand) = databaseFacade.CreateDbCommand(sql, commandType);
            dbConnection = _dbConnection;

            // 创建数据适配器并设置查询命令对象
            // EFCore 5.0 未提供 Sqlite DataAdapter
            var dbDataAdapter = DbProvider.IsDatabaseFor(databaseFacade.ProviderName, DbProvider.Sqlite) ? default : profiledDbProviderFactory.CreateDataAdapter();

                                if (dbDataAdapter != null)
                                {
                                    dbDataAdapter.SelectCommand = dbCommand;
                                }

                                // 返回
                                return(dbConnection, dbCommand, dbDataAdapter);
        }
Beispiel #2
0
        /// <summary>
        /// 修正不同数据库命令参数前缀不一致问题
        /// </summary>
        /// <param name="providerName"></param>
        /// <param name="parameterName"></param>
        /// <param name="isFixed"></param>
        /// <returns></returns>
        internal static string FixSqlParameterPlaceholder(string providerName, string parameterName, bool isFixed = true)
        {
            var placeholder = !DbProvider.IsDatabaseFor(providerName, DbProvider.Oracle) ? "@" : ":";

            if (parameterName.StartsWith("@") || parameterName.StartsWith(":"))
            {
                parameterName = parameterName[1..];
Beispiel #3
0
 /// <summary>
 /// 判断是否是 Dm 数据库
 /// </summary>
 /// <returns>bool</returns>
 public virtual bool IsDm()
 {
     return(DbProvider.IsDatabaseFor(ProviderName, DbProvider.Dm));
 }
Beispiel #4
0
 /// <summary>
 /// 判断是否是 Firebird 数据库
 /// </summary>
 /// <returns>bool</returns>
 public virtual bool IsFirebird()
 {
     return(DbProvider.IsDatabaseFor(ProviderName, DbProvider.Firebird));
 }
Beispiel #5
0
 /// <summary>
 /// 判断是否是 Oracle 数据库
 /// </summary>
 /// <returns>bool</returns>
 public virtual bool IsOracle()
 {
     return(DbProvider.IsDatabaseFor(ProviderName, DbProvider.Oracle));
 }
Beispiel #6
0
 /// <summary>
 /// 判断是否是 PostgreSQL 数据库
 /// </summary>
 /// <returns>bool</returns>
 public virtual bool IsNpgsql()
 {
     return(DbProvider.IsDatabaseFor(ProviderName, DbProvider.Npgsql));
 }
Beispiel #7
0
 /// <summary>
 /// 判断是否是 MySql 数据库 官方包(更新不及时,只支持 8.0.23+ 版本, 所以单独弄一个分类)
 /// </summary>
 /// <returns>bool</returns>
 public virtual bool IsMySqlOfficial()
 {
     return(DbProvider.IsDatabaseFor(ProviderName, DbProvider.MySqlOfficial));
 }
Beispiel #8
0
 /// <summary>
 /// 判断是否是 内存中 数据库
 /// </summary>
 /// <returns>bool</returns>
 public virtual bool InMemoryDatabase()
 {
     return(DbProvider.IsDatabaseFor(ProviderName, DbProvider.InMemoryDatabase));
 }
Beispiel #9
0
 /// <summary>
 /// 判断是否是 Cosmos 数据库
 /// </summary>
 /// <returns>bool</returns>
 public virtual bool IsCosmos()
 {
     return(DbProvider.IsDatabaseFor(ProviderName, DbProvider.Cosmos));
 }
Beispiel #10
0
 /// <summary>
 /// 判断是否是 Sqlite 数据库
 /// </summary>
 /// <returns>bool</returns>
 public virtual bool IsSqlite()
 {
     return(DbProvider.IsDatabaseFor(ProviderName, DbProvider.Sqlite));
 }
Beispiel #11
0
 /// <summary>
 /// 判断是否是 SqlServer 数据库
 /// </summary>
 /// <returns>bool</returns>
 public virtual bool IsSqlServer()
 {
     return(DbProvider.IsDatabaseFor(ProviderName, DbProvider.SqlServer));
 }