/// <summary> /// 分组指定字段名并返回当前语句 /// </summary> /// <typeparam name="T">实体类类型</typeparam> /// <param name="cmd">查询语句</param> /// <param name="expr">实体类属性</param> /// <exception cref="ExpressionInvalidException">表达式不正确</exception> /// <exception cref="NullAttributeException">没有设置特性</exception> /// <returns>当前语句</returns> /// <example> /// <code lang="C#"> /// <![CDATA[ /// public class UserRepository : DatabaseTable<User> /// { /// //other necessary code /// /// public DataTable GetAllEntities() /// { /// return this.Select() /// .Querys<User>(c => new { c.UserType }) /// .GroupBy<User>(c => c.UserType) /// .ToDataTable(this); /// /// //SELECT UserType From tbl_Users GROUP BY UserType /// } /// } /// ]]> /// </code> /// </example> public static SelectCommand GroupBy <T>(this SelectCommand cmd, Expression <Func <T, Object> > expr) { DatabaseColumnAttribute attr = SelectCommandExtension.GetColumnAttribute(cmd, expr.Body); return(cmd.GroupBy(attr.ColumnName)); }