/// <summary> /// 获取单个实体 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="cmd">选择语句</param> /// <param name="table">数据库表格</param> /// <exception cref="ArgumentNullException">选择语句或数据库表格不能为空</exception> /// <returns>数据实体</returns> /// <example> /// <code lang="C#"> /// <![CDATA[ /// public class UserRepository : AbstractDatabaseTable<User> /// { /// //other necessary code /// /// public User GetEntity(Int32 userID) /// { /// return this.Select() /// .Where(c => c.Equal(UserIDColumn, userID)) /// .ToEntity<User>(this); /// } /// } /// ]]> /// </code> /// </example> public static T ToEntity <T>(this SelectCommand cmd, AbstractDatabaseTable <T> table) where T : class { return(SelectCommandExtension.ToEntityWithArgs <T>(cmd, table, null)); }
/// <summary> /// 获取实体列表 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="cmd">选择语句</param> /// <param name="table">数据库表格</param> /// <param name="transaction">数据库事务</param> /// <exception cref="ArgumentNullException">选择语句或数据库表格不能为空</exception> /// <returns>数据实体列表</returns> public static List <T> ToEntityList <T>(this SelectCommand cmd, AbstractDatabaseTable <T> table, DbTransaction transaction) where T : class { return(SelectCommandExtension.ToEntityListWithArgs <T>(cmd, table, transaction, null)); }
/// <summary> /// 获取实体字典 /// </summary> /// <typeparam name="TKey">字典键类型</typeparam> /// <typeparam name="T">实体类型</typeparam> /// <param name="cmd">选择语句</param> /// <param name="table">数据库表格</param> /// <param name="keyColumnName">键列名称</param> /// <param name="transaction">数据库事务</param> /// <exception cref="ArgumentNullException">选择语句或数据库表格不能为空</exception> /// <returns>数据实体字典</returns> public static Dictionary <TKey, T> ToEntityDictionary <TKey, T>(this SelectCommand cmd, AbstractDatabaseTable <T> table, String keyColumnName, DbTransaction transaction) where T : class { return(SelectCommandExtension.ToEntityDictionaryWithArgs <TKey, T>(cmd, table, keyColumnName, transaction, null)); }
/// <summary> /// 获取实体数组 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="cmd">选择语句</param> /// <param name="table">数据库表格</param> /// <param name="connection">数据库连接</param> /// <exception cref="ArgumentNullException">选择语句或数据库表格不能为空</exception> /// <returns>数据实体数组</returns> public static T[] ToEntityArray <T>(this SelectCommand cmd, AbstractDatabaseTable <T> table, DbConnection connection) where T : class { return(SelectCommandExtension.ToEntityArrayWithArgs <T>(cmd, table, connection, null)); }