Skip to content

Commit 629ac62

Browse files
authored
Remove alias substitution for filtered many-to-many collection in hql (#2538)
It is no longer needed with table group joins
1 parent 19b2ad5 commit 629ac62

File tree

3 files changed

+3
-40
lines changed

3 files changed

+3
-40
lines changed

src/NHibernate/Loader/Hql/QueryLoader.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public partial class QueryLoader : BasicLoader
4545
private int _selectLength;
4646
private LockMode[] _defaultLockModes;
4747
private ISet<ICollectionPersister> _uncacheableCollectionPersisters;
48-
private Dictionary<string, string[]>[] _collectionUserProvidedAliases;
4948
private IReadOnlyDictionary<int, int> _entityByResultTypeDic;
5049

5150
public QueryLoader(QueryTranslatorImpl queryTranslator, ISessionFactoryImplementor factory, SelectClause selectClause)
@@ -204,11 +203,6 @@ protected internal override ICollectionPersister[] CollectionPersisters
204203
get { return _collectionPersisters; }
205204
}
206205

207-
protected override IDictionary<string, string[]> GetCollectionUserProvidedAlias(int index)
208-
{
209-
return _collectionUserProvidedAliases?[index];
210-
}
211-
212206
private void Initialize(SelectClause selectClause)
213207
{
214208
IList<FromElement> fromElementList = selectClause.FromElementsForLoad;
@@ -229,8 +223,6 @@ private void Initialize(SelectClause selectClause)
229223
_collectionPersisters = new IQueryableCollection[length];
230224
_collectionOwners = new int[length];
231225
_collectionSuffixes = new string[length];
232-
if (collectionFromElements.Any(qc => qc.QueryableCollection.IsManyToMany))
233-
_collectionUserProvidedAliases = new Dictionary<string, string[]>[length];
234226

235227
for (int i = 0; i < length; i++)
236228
{
@@ -280,24 +272,6 @@ private void Initialize(SelectClause selectClause)
280272
_selectLength++;
281273
}
282274

283-
if (collectionFromElements != null && element.IsFetch && element.QueryableCollection?.IsManyToMany == true
284-
&& element.QueryableCollection.IsManyToManyFiltered(_queryTranslator.EnabledFilters))
285-
{
286-
var collectionIndex = collectionFromElements.IndexOf(element);
287-
288-
if (collectionIndex >= 0)
289-
{
290-
// When many-to-many is filtered we need to populate collection from element persister and not from bridge table.
291-
// As bridge table will contain not-null values for filtered elements
292-
// So do alias substitution for collection persister with element persister
293-
// See test TestFilteredLinqQuery for details
294-
_collectionUserProvidedAliases[collectionIndex] = new Dictionary<string, string[]>
295-
{
296-
{CollectionPersister.PropElement, _entityPersisters[i].GetIdentifierAliases(Suffixes[i])}
297-
};
298-
}
299-
}
300-
301275
_owners[i] = -1; //by default
302276
if (element.IsFetch)
303277
{

src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,9 @@ public string GetManyToManyFilterFragment(string alias, IDictionary<string, IFil
13801380

13811381
return buffer.ToString();
13821382
}
1383-
1383+
1384+
// Since 5.4
1385+
[Obsolete("This method has no more usages and will be removed in a future version.")]
13841386
public bool IsManyToManyFiltered(IDictionary<string, IFilter> enabledFilters)
13851387
{
13861388
return IsManyToMany && (manyToManyWhereString != null || manyToManyFilterHelper.IsAffectedBy(enabledFilters));

src/NHibernate/Persister/Collection/ICollectionPersister.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,5 @@ public static int GetBatchSize(this ICollectionPersister persister)
305305

306306
return 1;
307307
}
308-
309-
/// <summary>
310-
/// Is this persister has enabled many-to-many filter or has many-to-many where clause
311-
/// </summary>
312-
internal static bool IsManyToManyFiltered(this ICollectionPersister persister, IDictionary<string, IFilter> enabledFilters)
313-
{
314-
if (persister is AbstractCollectionPersister acp)
315-
{
316-
return acp.IsManyToManyFiltered(enabledFilters);
317-
}
318-
319-
return persister.IsManyToMany && !string.IsNullOrEmpty(persister.GetManyToManyFilterFragment("x", enabledFilters));
320-
}
321308
}
322309
}

0 commit comments

Comments
 (0)