/// <summary> /// 获取单个实体 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="cmd">选择语句</param> /// <param name="table">数据库表格</param> /// <param name="args">创建实体时的额外参数</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)) /// .ToEntityWithArgs<User>(this, "argument"); /// } /// } /// ]]> /// </code> /// </example> public static T ToEntityWithArgs <T>(this SelectCommand cmd, AbstractDatabaseTable <T> table, Object args) where T : class { if (cmd == null) { throw new ArgumentNullException("cmd"); } if (table == null) { throw new ArgumentNullException("table"); } cmd.Top(1); return(table.InternalGetEntity(cmd, cmd.ToDataTable(), args)); }