ORM: 开发自己的Data Access Application Block - Part I
2008-12-06 10:15:45 来源:WEB开发网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
}
}
- ››开发Android 日历教程
- ››开发学院总结 Win 8实用技巧大全
- ››开发学院原创教程:把win8的IE10放桌面上方法(非...
- ››开发者眼中的Windows Phone和Android
- ››开发学院教你用SQL 语句最快速清空MySQL 数据表的...
- ››自己动手写iPhone wap浏览器之界面架构篇
- ››自己也能DIY个性真人QQ表情
- ››自己动手!巧法让酷狗动感歌词更完美
- ››自己编译Google Android内核的Linux源码
- ››自己写的一个jquery模板引擎(json比较好用)
- ››开发一个自己的HTML在线编辑器(一)
- ››开发一个自己的HTML在线编辑器(二)
更多精彩
赞助商链接