@@ -5,7 +5,6 @@ namespace NHibernate.Criterion
5
5
using Engine ;
6
6
using SqlCommand ;
7
7
using Type ;
8
- using Util ;
9
8
10
9
public static class CriterionUtil
11
10
{
@@ -51,13 +50,53 @@ internal static SqlString[] GetColumnNamesUsingProjection(IProjection projection
51
50
return GetColumnNamesUsingPropertyName ( criteriaQuery , criteria , propertyProjection . PropertyName ) ;
52
51
}
53
52
54
- SqlString sqlString = projection . ToSqlString ( criteria ,
55
- criteriaQuery . GetIndexForAlias ( ) ,
56
- criteriaQuery ) ;
57
- return new SqlString [ ]
58
- {
59
- SqlStringHelper . RemoveAsAliasesFromSql ( sqlString )
60
- } ;
53
+ return GetProjectionColumns ( projection , criteriaQuery , criteria ) ;
54
+ }
55
+
56
+ internal static object [ ] GetColumnNamesAsSqlStringParts ( string propertyName , IProjection projection , ICriteriaQuery criteriaQuery , ICriteria criteria )
57
+ {
58
+ if ( propertyName != null )
59
+ return criteriaQuery . GetColumnsUsingProjection ( criteria , propertyName ) ;
60
+
61
+ return GetColumnNamesAsSqlStringParts ( projection , criteriaQuery , criteria ) ;
62
+ }
63
+
64
+ internal static object [ ] GetColumnNamesAsSqlStringParts ( IProjection projection , ICriteriaQuery criteriaQuery , ICriteria criteria )
65
+ {
66
+ if ( projection is IPropertyProjection propertyProjection )
67
+ {
68
+ return criteriaQuery . GetColumnsUsingProjection ( criteria , propertyProjection . PropertyName ) ;
69
+ }
70
+
71
+ return GetProjectionColumns ( projection , criteriaQuery , criteria ) ;
72
+ }
73
+
74
+ internal static object GetColumnNameAsSqlStringPart ( string propertyName , IProjection projection , ICriteriaQuery criteriaQuery , ICriteria criteria )
75
+ {
76
+ var columnNames = GetColumnNamesAsSqlStringParts ( propertyName , projection , criteriaQuery , criteria ) ;
77
+ if ( columnNames . Length != 1 )
78
+ {
79
+ throw new QueryException ( "property or projection does not map to a single column: " + ( propertyName ?? projection . ToString ( ) ) ) ;
80
+ }
81
+
82
+ return columnNames [ 0 ] ;
83
+ }
84
+
85
+ internal static object GetColumnNameAsSqlStringPart ( IProjection projection , ICriteriaQuery criteriaQuery , ICriteria criteria )
86
+ {
87
+ var columnNames = GetColumnNamesAsSqlStringParts ( projection , criteriaQuery , criteria ) ;
88
+ if ( columnNames . Length != 1 )
89
+ {
90
+ throw new QueryException ( "property or projection does not map to a single column: " + ( projection . ToString ( ) ) ) ;
91
+ }
92
+
93
+ return columnNames [ 0 ] ;
94
+ }
95
+
96
+ private static SqlString [ ] GetProjectionColumns ( IProjection projection , ICriteriaQuery criteriaQuery , ICriteria criteria )
97
+ {
98
+ var sqlString = projection . ToSqlString ( criteria , criteriaQuery . GetIndexForAlias ( ) , criteriaQuery ) ;
99
+ return new [ ] { SqlStringHelper . RemoveAsAliasesFromSql ( sqlString ) } ;
61
100
}
62
101
63
102
private static SqlString [ ] GetColumnNamesUsingPropertyName ( ICriteriaQuery criteriaQuery , ICriteria criteria , string propertyName )
@@ -121,5 +160,18 @@ public static TypedValue[] GetTypedValues(ICriteriaQuery criteriaQuery, ICriteri
121
160
}
122
161
return types . ToArray ( ) ;
123
162
}
163
+
164
+ public static TypedValue GetTypedValue (
165
+ ICriteriaQuery criteriaQuery ,
166
+ ICriteria criteria ,
167
+ IProjection projection ,
168
+ string propertyName ,
169
+ object value )
170
+ {
171
+ if ( propertyName != null || ( propertyName = ( projection as IPropertyProjection ) ? . PropertyName ) != null )
172
+ return criteriaQuery . GetTypedValue ( criteria , propertyName , value ) ;
173
+
174
+ return new TypedValue ( NHibernateUtil . GuessType ( value ) , value ) ;
175
+ }
124
176
}
125
177
}
0 commit comments