public IDictionary <TKey, TValue> GroupbyMax <TKey, TValue>(Expression <Func <T, object> > keyField, Expression <Func <T, object> > valueField, LogicalBinaryExpression logical) { var parameters = CreateParamterCollection(); string sql = new Queryable <T>(DbReader) .Select(keyField) .Max(valueField) .Where(logical) .GroupBy(keyField) .OutputSqlString(parameters); using (var reader = DbReader.ExecuteReader(sql, parameters)) { return(reader.ToDictionary <TKey, TValue>()); } }