@@ -36,10 +36,9 @@ public FromElementType(FromElement fromElement, IEntityPersister persister, Enti
36
36
_persister = persister ;
37
37
_entityType = entityType ;
38
38
39
- if ( persister != null )
40
- {
41
- fromElement . Text = ( ( IQueryable ) persister ) . TableName + " " + TableAlias ;
42
- }
39
+ var queryable = persister as IQueryable ;
40
+ if ( queryable != null )
41
+ fromElement . Text = queryable . TableName + " " + fromElement . TableAlias ;
43
42
}
44
43
45
44
protected FromElementType ( FromElement fromElement )
@@ -111,22 +110,19 @@ public JoinSequence JoinSequence
111
110
{
112
111
get
113
112
{
114
- if ( _joinSequence != null )
113
+ if ( _joinSequence != null )
115
114
{
116
115
return _joinSequence ;
117
116
}
118
117
119
118
// Class names in the FROM clause result in a JoinSequence (the old FromParser does this).
120
- if ( _persister is IJoinable )
121
- {
122
- IJoinable joinable = ( IJoinable ) _persister ;
123
- return _fromElement . SessionFactoryHelper . CreateJoinSequence ( ) . SetRoot ( joinable , TableAlias ) ;
124
- }
125
- else
119
+ var joinable = _persister as IJoinable ;
120
+ if ( joinable != null )
126
121
{
127
- return null ; // TODO: Should this really return null? If not, figure out something better to do here.
122
+ return _fromElement . SessionFactoryHelper . CreateJoinSequence ( ) . SetRoot ( joinable , TableAlias ) ;
128
123
}
129
124
125
+ return null ; // TODO: Should this really return null? If not, figure out something better to do here.
130
126
}
131
127
set { _joinSequence = value ; }
132
128
}
@@ -144,11 +140,14 @@ public string RenderIdentifierSelect(int size, int k)
144
140
// Render the identifier select fragment using the table alias.
145
141
if ( _fromElement . FromClause . IsSubQuery )
146
142
{
143
+ var queryable = Queryable ;
144
+ if ( queryable == null )
145
+ return string . Empty ;
146
+
147
147
// TODO: Replace this with a more elegant solution.
148
- string [ ] idColumnNames = ( _persister != null ) ?
149
- ( ( IQueryable ) _persister ) . IdentifierColumnNames : new String [ 0 ] ;
148
+ string [ ] idColumnNames = queryable . IdentifierColumnNames ;
150
149
151
- StringBuilder buf = new StringBuilder ( ) ;
150
+ var buf = new StringBuilder ( ) ;
152
151
for ( int i = 0 ; i < idColumnNames . Length ; i ++ )
153
152
{
154
153
buf . Append ( _fromElement . TableAlias ) . Append ( '.' ) . Append ( idColumnNames [ i ] ) ;
@@ -158,11 +157,11 @@ public string RenderIdentifierSelect(int size, int k)
158
157
}
159
158
else
160
159
{
161
- if ( _persister == null )
162
- {
160
+ var queryable = Queryable ;
161
+ if ( queryable == null )
163
162
throw new QueryException ( "not an entity" ) ;
164
- }
165
- string fragment = ( ( IQueryable ) _persister ) . IdentifierSelectFragment ( TableAlias , GetSuffix ( size , k ) ) ;
163
+
164
+ string fragment = queryable . IdentifierSelectFragment ( TableAlias , GetSuffix ( size , k ) ) ;
166
165
return TrimLeadingCommaAndSpaces ( fragment ) ;
167
166
}
168
167
}
@@ -202,53 +201,37 @@ public string RenderPropertySelect(int size, int k, bool allProperties)
202
201
{
203
202
CheckInitialized ( ) ;
204
203
205
- if ( _persister == null )
206
- {
204
+ var queryable = Queryable ;
205
+ if ( queryable == null )
207
206
return "" ;
208
- }
209
- else
210
- {
211
- string fragment = ( ( IQueryable ) _persister ) . PropertySelectFragment (
212
- TableAlias ,
213
- GetSuffix ( size , k ) ,
214
- allProperties
215
- ) ;
216
- return TrimLeadingCommaAndSpaces ( fragment ) ;
217
- }
207
+
208
+ string fragment = queryable . PropertySelectFragment ( TableAlias , GetSuffix ( size , k ) , allProperties ) ;
209
+
210
+ return TrimLeadingCommaAndSpaces ( fragment ) ;
218
211
}
219
212
220
213
public string RenderCollectionSelectFragment ( int size , int k )
221
214
{
222
215
if ( _queryableCollection == null )
223
- {
224
216
return "" ;
225
- }
226
- else
227
- {
228
- if ( _collectionSuffix == null )
229
- {
230
- _collectionSuffix = GenerateSuffix ( size , k ) ;
231
- }
232
- string fragment = _queryableCollection . SelectFragment ( CollectionTableAlias , _collectionSuffix ) ;
233
- return TrimLeadingCommaAndSpaces ( fragment ) ;
234
- }
217
+
218
+ if ( _collectionSuffix == null )
219
+ _collectionSuffix = GenerateSuffix ( size , k ) ;
220
+
221
+ string fragment = _queryableCollection . SelectFragment ( CollectionTableAlias , _collectionSuffix ) ;
222
+ return TrimLeadingCommaAndSpaces ( fragment ) ;
235
223
}
236
224
237
225
public string RenderValueCollectionSelectFragment ( int size , int k )
238
226
{
239
227
if ( _queryableCollection == null )
240
- {
241
228
return "" ;
242
- }
243
- else
244
- {
245
- if ( _collectionSuffix == null )
246
- {
247
- _collectionSuffix = GenerateSuffix ( size , k ) ;
248
- }
249
- string fragment = _queryableCollection . SelectFragment ( TableAlias , _collectionSuffix ) ;
250
- return TrimLeadingCommaAndSpaces ( fragment ) ;
251
- }
229
+
230
+ if ( _collectionSuffix == null )
231
+ _collectionSuffix = GenerateSuffix ( size , k ) ;
232
+
233
+ string fragment = _queryableCollection . SelectFragment ( TableAlias , _collectionSuffix ) ;
234
+ return TrimLeadingCommaAndSpaces ( fragment ) ;
252
235
}
253
236
254
237
public bool IsEntity
@@ -258,23 +241,15 @@ public bool IsEntity
258
241
259
242
public bool IsCollectionOfValuesOrComponents
260
243
{
261
- get
244
+ get
262
245
{
263
- if ( _persister == null )
264
- {
265
- if ( _queryableCollection == null )
266
- {
267
- return false ;
268
- }
269
- else
270
- {
271
- return ! _queryableCollection . ElementType . IsEntityType ;
272
- }
273
- }
274
- else
275
- {
246
+ if ( _persister != null )
276
247
return false ;
277
- }
248
+
249
+ if ( _queryableCollection == null )
250
+ return false ;
251
+
252
+ return ! _queryableCollection . ElementType . IsEntityType ;
278
253
}
279
254
}
280
255
@@ -361,7 +336,7 @@ public string[] ToColumns(string tableAlias, string path, bool inSelect)
361
336
/// </summary>
362
337
public IQueryable Queryable
363
338
{
364
- get { return ( _persister is IQueryable ) ? ( IQueryable ) _persister : null ; }
339
+ get { return _persister as IQueryable ; }
365
340
}
366
341
367
342
public virtual IQueryableCollection QueryableCollection
@@ -379,7 +354,6 @@ public virtual IQueryableCollection QueryableCollection
379
354
// For many-to-many joins, use the tablename from the queryable collection for the default text.
380
355
_fromElement . Text = _queryableCollection . TableName + " " + TableAlias ;
381
356
}
382
-
383
357
}
384
358
}
385
359
@@ -481,7 +455,7 @@ private bool IsCorrelation
481
455
{
482
456
FromClause top = _fromElement . Walker . GetFinalFromClause ( ) ;
483
457
return _fromElement . FromClause != _fromElement . Walker . CurrentFromClause &&
484
- _fromElement . FromClause == top ;
458
+ _fromElement . FromClause == top ;
485
459
}
486
460
}
487
461
@@ -491,7 +465,7 @@ private bool IsMultiTable
491
465
{
492
466
// should be safe to only ever expect EntityPersister references here
493
467
return _fromElement . Queryable != null &&
494
- _fromElement . Queryable . IsMultiTable ;
468
+ _fromElement . Queryable . IsMultiTable ;
495
469
}
496
470
}
497
471
@@ -516,6 +490,5 @@ private static string TrimLeadingCommaAndSpaces(String fragment)
516
490
fragment = fragment . Trim ( ) ;
517
491
return fragment . Trim ( ) ;
518
492
}
519
-
520
493
}
521
494
}
0 commit comments