/// <summary> /// Maps a data row to an object /// </summary> /// <typeparam name="T">Type of object to map the data to</typeparam> /// <typeparam name="TIdType">Type of the unique identifier of the object</typeparam> /// <param name="row">Data row containing the row being mapped</param> /// <param name="conn">Open connection to the database</param> /// <returns>Data row, mapped to an object</returns> private static T ExecuteMappedSingleReader <T, TIdType>(db.DbConnection conn, sp.DataRow row) where T : DbObject <TIdType> { //create a new item DbObject <TIdType> item = Activator.CreateInstance <T>() as DbObject <TIdType>; item.Load(conn, row); return((T)item); }
/// <summary> /// Executes a command and maps each row to an object /// </summary> /// <typeparam name="T">Type of object to map the data to</typeparam> /// <typeparam name="TIdType">Type of the unique identifier of the object</typeparam> /// <param name="mapper">Mapper used to map the data to an object</param> /// <returns>Each row selected by the command, mapped to an object</returns> public T[] ExecuteMappedReader <T, TIdType>(Func <sp.DataRow, T> mapper) { sp.DataTable dt = ExecuteReader(); return(ExecuteMappedReader <T>(dt, row => { T item = mapper(row); DbObject <TIdType> dbObject = item as DbObject <TIdType>; if (dbObject != null) { dbObject.SetIsInDatabase(true); } return item; })); }