@@ -115,10 +115,14 @@ public string GetQuotedName(Dialect.Dialect d)
115
115
return IsQuoted ? d . QuoteForColumnName ( _name ) : _name ;
116
116
}
117
117
118
+ // Accomodate the one character suffix appended in AbstractCollectionPersister and
119
+ // the SelectFragment suffix up to 99 joins.
120
+ private const int _charactersLeftCount = 4 ;
118
121
119
122
/// <summary>
120
123
/// For any column name, generate an alias that is unique to that
121
124
/// column name, and also take Dialect.MaxAliasLength into account.
125
+ /// It keeps four characters left for accommodating additional suffixes.
122
126
/// </summary>
123
127
public string GetAlias ( Dialect . Dialect dialect )
124
128
{
@@ -127,6 +131,7 @@ public string GetAlias(Dialect.Dialect dialect)
127
131
128
132
private string GetAlias ( int maxAliasLength )
129
133
{
134
+ var usableLength = maxAliasLength - _charactersLeftCount ;
130
135
var name = CanonicalName ;
131
136
string alias = name ;
132
137
string suffix = UniqueInteger . ToString ( ) + StringHelper . Underscore ;
@@ -148,25 +153,27 @@ private string GetAlias(int maxAliasLength)
148
153
// reason, the checks for "_quoted" and "rowid" looks redundant. If you remove
149
154
// those checks, then the double checks for total length can be reduced to one.
150
155
// But I will leave it like this for now to make it look similar. /Oskar 2016-08-20
151
- bool useRawName = name . Length + suffix . Length <= maxAliasLength &&
156
+ bool useRawName = name . Length + suffix . Length <= usableLength &&
152
157
! _quoted &&
153
158
! StringHelper . EqualsCaseInsensitive ( name , "rowid" ) ;
154
159
if ( ! useRawName )
155
160
{
156
- if ( suffix . Length >= maxAliasLength )
161
+ if ( suffix . Length >= usableLength )
157
162
{
158
163
throw new MappingException (
159
- string . Format (
160
- "Unique suffix {0} length must be less than maximum {1} characters." ,
161
- suffix ,
162
- maxAliasLength ) ) ;
164
+ $ "Unique suffix { suffix } length must be less than maximum { usableLength } characters.") ;
163
165
}
164
- if ( alias . Length + suffix . Length > maxAliasLength )
165
- alias = alias . Substring ( 0 , maxAliasLength - suffix . Length ) ;
166
+ if ( alias . Length + suffix . Length > usableLength )
167
+ alias = alias . Substring ( 0 , usableLength - suffix . Length ) ;
166
168
}
167
169
return alias + suffix ;
168
170
}
169
171
172
+ /// <summary>
173
+ /// For any column name, generate an alias that is unique to that
174
+ /// column name and table, and also take Dialect.MaxAliasLength into account.
175
+ /// It keeps four characters left for accommodating additional suffixes.
176
+ /// </summary>
170
177
public string GetAlias ( Dialect . Dialect dialect , Table table )
171
178
{
172
179
string suffix = table . UniqueInteger . ToString ( ) + StringHelper . Underscore ;
0 commit comments