WEB开发网
开发学院数据库MSSQL Server ORM: 开发自己的Data Access Application Block -... 阅读

ORM: 开发自己的Data Access Application Block - Part I

 2008-12-06 10:15:45 来源:WEB开发网   
核心提示: DatabaseFactory: 一个静态的类,根据配置的信息创建你需要的具体的Database对象,ORM: 开发自己的Data Access Application Block - Part I(3),实现泛型化编程,DataAccessConfigurationCollection,

DatabaseFactory: 一个静态的类,根据配置的信息创建你需要的具体的Database对象,实现泛型化编程。

DataAccessConfigurationCollection,DataAccessConfigurationElement,DataAccessConfigurationSection 三个Configuration的Class。

为了使大家清楚地看出这个Application block所有的操作,我把所有的操作封装在一个IDatabase的interface中,不过需要注意的是,我采用的是基于Abstract class的编程,而不是基于Interface的编程,相信大家对这两种方式讨论得已经碰倒的太多了,孰优孰劣我就不想对说了。这个IDatabase 接口,只是展示所有Operation之用,并没有在我的代码中用到。

namespace Artech.ApplicationBlock.DataAccess
{
  public interface IDatabase
  {
    Fill a System.Data.DataSet with retrieved data.#region Fill a System.Data.DataSet with retrieved data.
    void FillDataSet(DataSet dataInfo, string commandText, IDictionary<string, object> parameters);
    void FillDataSet(DataSet dataInfo, string tableName, string commandText, IDictionary<string, object> parameters);
    void FillDataSet(DataSet dataInfo, string tableName, CommandType commandType, string commandText, IDictionary<string, object> parameters);
    #endregion
    Save the changed data which is stored in a dataset into database.#region Save the changed data which is stored in a dataset into database.
    void UpdateData(DataSet dataInfo);
    void UpdateData(DataTable table);
    void UpdateData(DataTable table, string insertCommandText, string updateCommandText, string deleteCommandText,
      Dictionary<string, object> insertParameters, Dictionary<string, object> updateParameters, Dictionary<string, object> deleteParameters);
        void UpdateData(DataTable table, CommandType commandType, string insertCommandText, string updateCommandText, string deleteCommandText,
      Dictionary<string, object> insertParameters, Dictionary<string, object> updateParameters, Dictionary<string, object> deleteParameters);
    void UpdateData(DataTable table, DbCommand insertCommand, DbCommand updateCommand, DbCommand deleteCommand);
    #endregion
    Execute a command and return the affect row count.#region Execute a command and return the affect row count.
    int ExecuteNonQuery(CommandType commandType, string commandText, Dictionary<string, object> inputParameters, Dictionary<string, object> outputParameters);
    int ExecuteNonQuery(CommandType commandType, string commandText, Dictionary<string, object> inputParameters);
    int ExecuteNonQuery( string commandText, Dictionary<string, object> inputParameters, Dictionary<string, object> outputParameters);
    int ExecuteNonQuery( string commandText, Dictionary<string, object> inputParameters);
    #endregion
    Execute a command and return the data in the form of data reader.#region Execute a command and return the data in the form of data reader.
    DbDataReader ExecuteReader(CommandType commandType, string commandText, Dictionary<string, object> inputParameters, Dictionary<string, object> outputParameters);
    DbDataReader ExecuteReader(CommandType commandType, string commandText, Dictionary<string, object> inputParameters);
    DbDataReader ExecuteReader(string commandText, Dictionary<string, object> inputParameters, Dictionary<string, object> outputParameters);
    DbDataReader ExecuteReader(string commandText, Dictionary<string, object> inputParameters);
    #endregion
    Execute a command and return a scalar value.#region Execute a command and return a scalar value.
    object ExecuteScalar(CommandType commandType, string commandText, Dictionary<string, object> inputParameters, Dictionary<string, object> outputParameters);
    object ExecuteScalar(CommandType commandType, string commandText, Dictionary<string, object> inputParameters);
    object ExecuteScalar(string commandText, Dictionary<string, object> inputParameters, Dictionary<string, object> outputParameters);
    object ExecuteScalar(string commandText, Dictionary<string, object> inputParameters);
    #endregion
    Transaction based operation#region Transaction based operation
    void BeginTransaction();
    void Commit();
    void RollBack();
    #endregion
  }
}

上一页  1 2 3 4 5 6 7 8  下一页

Tags:ORM 开发 自己

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接