@@ -263,7 +263,7 @@ public virtual void BindValues(DbCommand ps)
263263
264264 // This must be a Lazy<T>, because instances of this class must be thread safe.
265265 private readonly Lazy < string [ ] > defaultUniqueKeyPropertyNamesForSelectId ;
266- private readonly Dictionary < string , int > propertyTableNumbersByNameAndSubclass = new Dictionary < string , int > ( ) ;
266+ private readonly Dictionary < string , int > propertySubclassJoinTableNumbersByName ;
267267
268268 protected AbstractEntityPersister ( PersistentClass persistentClass , ICacheConcurrencyStrategy cache ,
269269 ISessionFactoryImplementor factory )
@@ -441,6 +441,17 @@ protected AbstractEntityPersister(PersistentClass persistentClass, ICacheConcurr
441441 List < bool > columnSelectables = new List < bool > ( ) ;
442442 List < bool > propNullables = new List < bool > ( ) ;
443443
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+
444455 foreach ( Property prop in persistentClass . SubclassPropertyClosureIterator )
445456 {
446457 names . Add ( prop . Name ) ;
@@ -449,8 +460,6 @@ protected AbstractEntityPersister(PersistentClass persistentClass, ICacheConcurr
449460 definedBySubclass . Add ( isDefinedBySubclass ) ;
450461 propNullables . Add ( prop . IsOptional || isDefinedBySubclass ) ; //TODO: is this completely correct?
451462 types . Add ( prop . Type ) ;
452- propertyTableNumbersByNameAndSubclass [ prop . PersistentClass . EntityName + '.' + prop . Name ] =
453- persistentClass . GetJoinNumber ( prop ) ;
454463
455464 string [ ] cols = new string [ prop . ColumnSpan ] ;
456465 string [ ] forms = new string [ prop . ColumnSpan ] ;
@@ -1125,12 +1134,15 @@ protected virtual bool IsIdOfTable(int property, int table)
11251134
11261135 protected abstract int GetSubclassPropertyTableNumber ( int i ) ;
11271136
1128- internal int GetSubclassPropertyTableNumber ( string propertyName , string entityName )
1137+ internal int GetSubclassJoinPropertyTableNumber ( string propertyName , string entityName )
11291138 {
1139+ if ( propertySubclassJoinTableNumbersByName == null )
1140+ return 0 ;
1141+
11301142 var type = propertyMapping . ToType ( propertyName ) ;
11311143 if ( type . IsAssociationType && ( ( IAssociationType ) type ) . UseLHSPrimaryKey )
11321144 return 0 ;
1133- propertyTableNumbersByNameAndSubclass . TryGetValue ( entityName + '.' + propertyName , out var tabnum ) ;
1145+ propertySubclassJoinTableNumbersByName . TryGetValue ( entityName + '.' + propertyName , out var tabnum ) ;
11341146 return tabnum ;
11351147 }
11361148
@@ -4878,7 +4890,7 @@ internal SqlString GenerateSequentialSelect(AbstractEntityPersister subclassPers
48784890 var classes = subclassPersister . PropertySubclassNames ;
48794891 for ( var i = 0 ; i < props . Length ; i ++ )
48804892 {
4881- var propTableNumber = GetSubclassPropertyTableNumber ( props [ i ] , classes [ i ] ) ;
4893+ var propTableNumber = GetSubclassJoinPropertyTableNumber ( props [ i ] , classes [ i ] ) ;
48824894 if ( IsSubclassTableSequentialSelect ( propTableNumber ) && ! IsSubclassTableLazy ( propTableNumber ) )
48834895 {
48844896 tableNumbers . Add ( propTableNumber ) ;
0 commit comments