@@ -263,7 +263,7 @@ public virtual void BindValues(DbCommand ps)
263
263
264
264
// This must be a Lazy<T>, because instances of this class must be thread safe.
265
265
private readonly Lazy < string [ ] > defaultUniqueKeyPropertyNamesForSelectId ;
266
- private readonly Dictionary < string , int > propertyTableNumbersByNameAndSubclass = new Dictionary < string , int > ( ) ;
266
+ private readonly Dictionary < string , int > propertySubclassJoinTableNumbersByName ;
267
267
268
268
protected AbstractEntityPersister ( PersistentClass persistentClass , ICacheConcurrencyStrategy cache ,
269
269
ISessionFactoryImplementor factory )
@@ -441,6 +441,17 @@ protected AbstractEntityPersister(PersistentClass persistentClass, ICacheConcurr
441
441
List < bool > columnSelectables = new List < bool > ( ) ;
442
442
List < bool > propNullables = new List < bool > ( ) ;
443
443
444
+ if ( persistentClass . SubclassJoinClosureIterator . Any ( ) )
445
+ {
446
+ propertySubclassJoinTableNumbersByName = new Dictionary < string , int > ( ) ;
447
+ foreach ( Property prop in persistentClass . SubclassPropertyClosureIterator )
448
+ {
449
+ var joinNumber = persistentClass . GetJoinNumber ( prop ) ;
450
+ if ( joinNumber != 0 )
451
+ propertySubclassJoinTableNumbersByName [ prop . PersistentClass . EntityName + '.' + prop . Name ] = joinNumber ;
452
+ }
453
+ }
454
+
444
455
foreach ( Property prop in persistentClass . SubclassPropertyClosureIterator )
445
456
{
446
457
names . Add ( prop . Name ) ;
@@ -449,8 +460,6 @@ protected AbstractEntityPersister(PersistentClass persistentClass, ICacheConcurr
449
460
definedBySubclass . Add ( isDefinedBySubclass ) ;
450
461
propNullables . Add ( prop . IsOptional || isDefinedBySubclass ) ; //TODO: is this completely correct?
451
462
types . Add ( prop . Type ) ;
452
- propertyTableNumbersByNameAndSubclass [ prop . PersistentClass . EntityName + '.' + prop . Name ] =
453
- persistentClass . GetJoinNumber ( prop ) ;
454
463
455
464
string [ ] cols = new string [ prop . ColumnSpan ] ;
456
465
string [ ] forms = new string [ prop . ColumnSpan ] ;
@@ -1125,12 +1134,15 @@ protected virtual bool IsIdOfTable(int property, int table)
1125
1134
1126
1135
protected abstract int GetSubclassPropertyTableNumber ( int i ) ;
1127
1136
1128
- internal int GetSubclassPropertyTableNumber ( string propertyName , string entityName )
1137
+ internal int GetSubclassJoinPropertyTableNumber ( string propertyName , string entityName )
1129
1138
{
1139
+ if ( propertySubclassJoinTableNumbersByName == null )
1140
+ return 0 ;
1141
+
1130
1142
var type = propertyMapping . ToType ( propertyName ) ;
1131
1143
if ( type . IsAssociationType && ( ( IAssociationType ) type ) . UseLHSPrimaryKey )
1132
1144
return 0 ;
1133
- propertyTableNumbersByNameAndSubclass . TryGetValue ( entityName + '.' + propertyName , out var tabnum ) ;
1145
+ propertySubclassJoinTableNumbersByName . TryGetValue ( entityName + '.' + propertyName , out var tabnum ) ;
1134
1146
return tabnum ;
1135
1147
}
1136
1148
@@ -4878,7 +4890,7 @@ internal SqlString GenerateSequentialSelect(AbstractEntityPersister subclassPers
4878
4890
var classes = subclassPersister . PropertySubclassNames ;
4879
4891
for ( var i = 0 ; i < props . Length ; i ++ )
4880
4892
{
4881
- var propTableNumber = GetSubclassPropertyTableNumber ( props [ i ] , classes [ i ] ) ;
4893
+ var propTableNumber = GetSubclassJoinPropertyTableNumber ( props [ i ] , classes [ i ] ) ;
4882
4894
if ( IsSubclassTableSequentialSelect ( propTableNumber ) && ! IsSubclassTableLazy ( propTableNumber ) )
4883
4895
{
4884
4896
tableNumbers . Add ( propTableNumber ) ;
0 commit comments