开发自己的Data Access Application Block[下篇]
上接: [原创] 我的ORM: 开发自己的Data Access Application Block - Part I 4. Database 下面来介绍重中之重:Database,绝大部分的DataAccess 操作都集中在这个Abstract Database中。这是一个相对庞大的Class,所以不得不采用Partial Class的方式来编写。
上接:[原创] 我的ORM: 开发自己的Data Access Application Block - Part I4. Database
下面来介绍重中之重:Database,绝大部分的Data Access 操作都集中在这个Abstract Database中。这是一个相对庞大的Class,所以不得不采用Partial Class的方式来编写。
Part I:Field 和Property
这些Field 和Property基本上对应我们前面的Configuraiton。此为我们定义了三个Field 和Property:DbDataAdapter,Connection,_transaction。考虑到垃圾回收,使Database实现IDisposable接口。值得说明一点的是,我们通过Database的DatabaseProviderFactory创建了泛型的DbDataAdapter,DbConnection和Transaction。
-
ConnectionString:string
-
DatabaseProviderFactory:DbProviderFactory
-
DefaultCommandType:CommandType
-
UseCommandBuilder:bool
-
DbParameterNameMapping:IDbParameterNameMapping
-
StoredProcedureNameMapping:IStoredProcedureNameMapping
-
DbDataAdapter:DbDataAdapter
-
Connection: DbConnection
-
Transaction: DbTransaction
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using Artech.ApplicationBlock.DataMapping;
namespace Artech.ApplicationBlock.DataAccess
{
/**////
/// Database defines a series of database-based operations.
///
public abstract partial class Database : IDisposable
{
private bool _isDisposed;
The five private fields possess the corressponding pubic properties, and they are only allowed to be evaluated by Database Factory.#region The five private fields possess the corressponding pubic properties, and they are only allowed to be evaluated by Database Factory.
private DbProviderFactory _dbProviderFactory;
private string _connectionString;
private CommandType _defaultCommandType;
private bool _useCommandBuilder;
private IDbParameterNameMapping _dbParameterNameMapping;
private IStoredProcedureNameMapping _storedProcedureNameMapping;
/**////
/// Database connection string which is specified by the database factory.
///
public string ConnectionString
{
get
{
return this._connectionString;
}
set
{
this._connectionString = value;
}
}
/**////
/// The concrete database specific provider factory.
///
public DbProviderFactory DatabaseProviderFactory
{
get
{
return this._dbProviderFactory;
}
set
{
this._dbProviderFactory = value;
}
}
/**////
/// The defaull command type to perform the database operations which do not specify the commanf type.
///
public CommandType DefaultCommandType
{
get
{
return this._defaultCommandType;
}
set
{
this._defaultCommandType = value;
}
}
/**////
///Determine whether to use command builder or mapped stored procedures to execute database operations.
///
public bool UseCommandBuilder
{
get
{
return this._useCommandBuilder;
}
set
{
this._useCommandBuilder = value;
}
}
/**////
/// A string which indicates the type to perform mapping between stored procedure parameter and source column.
///
public IDbParameterNameMapping DbParameterNameMapping
{
get
{
return this._dbParameterNameMapping;
}
set
{
this._dbParameterNameMapping = value;
}
}
/**////
/// A string which indicates the type to perform mapping between table name and the related stored procedure names.
///
public IStoredProcedureNameMapping StoredProcedureNameMapping
{
get
{
return this._storedProcedureNameMapping;
}
set
{
this._storedProcedureNameMapping = value;
}
}
#endregion
Connection & Database DataAdapter#region Connection & Database DataAdapter
private DbDataAdapter _dbDataAdapter;
private DbConnection _connection;
/**////
/// A generic database data adapter which is responsible for save the changed data into database.
///
private DbDataAdapter DatabaseAdapter
{
get
{
if (this._dbDataAdapter == null)
{
this._dbDataAdapter = this._dbProviderFactory.CreateDataAdapter();
this._dbDataAdapter.AcceptChangesDuringUpdate = false;
this._dbDataAdapter.MissingSchemaAction = MissingSchemaAction.Add;
}
return this._dbDataAdapter;
}
}
/**////
/// The database connection.
///
private DbConnection Connection
{
get
{
if (this._connection == null)
{
this._connection = this._dbProviderFactory.CreateConnection();
this._connection.ConnectionString = this._connectionString;
}
return this._connection;
}
}
#endregion
Constructor#region Constructor
public Database()
&

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

SQL IF 語句用於有條件地執行 SQL 語句,語法為: IF (condition) THEN {語句} ELSE {語句} END IF;。條件可以是任何有效的 SQL 表達式,如果條件為真,執行 THEN 子句;如果條件為假,執行 ELSE 子句。 IF 語句可以嵌套,允許更複雜的條件檢查。

解決 Vue Axios 跨域問題的方法包括:服務器端配置 CORS 頭使用 Axios 代理使用 JSONP使用 WebSocket使用 CORS 插件

如何在 Apache 中配置 Zend?在 Apache Web 服務器中配置 Zend Framework 的步驟如下:安裝 Zend Framework 並解壓到 Web 服務器目錄中。創建 .htaccess 文件。創建 Zend 應用程序目錄並添加 index.php 文件。配置 Zend 應用程序(application.ini)。重新啟動 Apache Web 服務器。

多線程的好處在於能提升性能和資源利用率,尤其適用於處理大量數據或執行耗時操作。它允許同時執行多個任務,提高效率。然而,線程過多會導致性能下降,因此需要根據 CPU 核心數和任務特性謹慎選擇線程數。另外,多線程編程涉及死鎖和競態條件等挑戰,需要使用同步機制解決,需要具備紮實的並發編程知識,權衡利弊並謹慎使用。

無法以 root 身份登錄 MySQL 的原因主要在於權限問題、配置文件錯誤、密碼不符、socket 文件問題或防火牆攔截。解決方法包括:檢查配置文件中 bind-address 參數是否正確配置。查看 root 用戶權限是否被修改或刪除,並進行重置。驗證密碼是否準確無誤,包括大小寫和特殊字符。檢查 socket 文件權限設置和路徑。檢查防火牆是否阻止了 MySQL 服務器的連接。

本文介紹如何在Debian系統上有效監控Nginx服務器的SSL性能。我們將使用NginxExporter將Nginx狀態數據導出到Prometheus,再通過Grafana進行可視化展示。第一步:配置Nginx首先,我們需要在Nginx配置文件中啟用stub_status模塊來獲取Nginx的狀態信息。在你的Nginx配置文件(通常位於/etc/nginx/nginx.conf或其包含文件中)中添加以下代碼段:location/nginx_status{stub_status

PHPMyAdmin安全防禦策略的關鍵在於:1. 使用最新版PHPMyAdmin及定期更新PHP和MySQL;2. 嚴格控制訪問權限,使用.htaccess或Web服務器訪問控制;3. 啟用強密碼和雙因素認證;4. 定期備份數據庫;5. 仔細檢查配置文件,避免暴露敏感信息;6. 使用Web應用防火牆(WAF);7. 進行安全審計。 這些措施能夠有效降低PHPMyAdmin因配置不當、版本過舊或環境安全隱患導致的安全風險,保障數據庫安全。

vProcesserazrabotkiveb被固定,мнелостольностьстьс粹餾標д都LeavallySumballanceFriablanceFaumDoptoMatification,Čtookazalovnetakprosto,kakaožidal.posenesko
