Cps DbHelper is a set of class designed to wrap Ado.net in chained method calls.
The goal is to try my best to simplify the code of using ado.net as much as possible.
- Using chained method call so that the action can be prepared before executing
- Auto map class with data column
- Auto map class with user defined structured types
- Cache the maps to improve performance.
- Ability to cache the query result.
- Support Xml and Xml auto map
with this wrapper. sql server calls can be written this way:
/// <summary>
/// executes a stored procedure returns one result set and the columns matches the entity properties
/// </summary>
/// <param name="id">an optional id parameter</param>
/// <returns></returns>
public IEnumerable<Person> GetPersion(int? id)
{
var reader = _db.BeginReader("sp_getPeople")
.AddIntInParam("Id", id)
.AddOutParam("totalCount", SqlDbType.Int)
//the result key is used to identify result set, the default value can be used once
.AutoMapResult<Person>()
//the same as this way:
//.BeginMapResult<Person>().AutoMap().FinishMap()
.Execute();
//retrieve the result. the reader always use a List<T> to store the returned table.
var ret = reader.GetResult<IList<Person>>(); //the result key is default as the one when mapping.
//retrive the output parameter with it's name.
var count = reader.GetParamResult<int>("totalCount");
return ret;
}