Skip to content

Commit 5a6dc6a

Browse files
author
g.yakimov
committed
improve adding of with clauses
1 parent a4b341c commit 5a6dc6a

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ private bool TryGetColumns(ICriteria subcriteria, string path, bool verifyProper
766766
return false;
767767
}
768768

769-
columns = propertyMapping.ToColumns(GetSQLAlias(pathCriteria), propertyName);
769+
columns = propertyMapping.ToColumns(pathCriteria, propertyName, GetSQLAlias);
770770
return true;
771771
}
772772

src/NHibernate/Persister/Entity/AbstractPropertyMapping.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public bool TryToType(string propertyName, out IType type)
4444
return typesByPropertyPath.TryGetValue(propertyName, out type);
4545
}
4646

47+
public virtual string[] ToColumns(ICriteria pathCriteria, string propertyName, Func<ICriteria, string> getSQLAlias)
48+
{
49+
string alias = getSQLAlias(pathCriteria);
50+
return ToColumns(alias, propertyName);
51+
}
52+
4753
public virtual string[] ToColumns(string alias, string propertyName)
4854
{
4955
//TODO: *two* hashmap lookups here is one too many...

src/NHibernate/Persister/Entity/BasicEntityPropertyMapping.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
using System;
2+
using NHibernate.Criterion;
13
using NHibernate.Type;
4+
using static NHibernate.Impl.CriteriaImpl;
25

36
namespace NHibernate.Persister.Entity
47
{
@@ -26,6 +29,17 @@ public override IType Type
2629
get { return persister.Type; }
2730
}
2831

32+
public override string[] ToColumns(ICriteria pathCriteria, string propertyName, Func<ICriteria, string> getSQLAlias)
33+
{
34+
var withClause = pathCriteria as Subcriteria != null ? ((Subcriteria)pathCriteria).WithClause as SimpleExpression : null;
35+
if (withClause != null && withClause.PropertyName == propertyName)
36+
{
37+
return base.ToColumns(persister.GenerateTableAlias(getSQLAlias(pathCriteria), 0), propertyName);
38+
}
39+
40+
return base.ToColumns(pathCriteria, propertyName, getSQLAlias);
41+
}
42+
2943
public override string[] ToColumns(string alias, string propertyName)
3044
{
3145
return

src/NHibernate/Persister/Entity/IPropertyMapping.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public interface IPropertyMapping
2929
/// <returns>true if a type was found, false if not</returns>
3030
bool TryToType(string propertyName, out IType type);
3131

32+
string[] ToColumns(ICriteria pathCriteria, string propertyName, System.Func<ICriteria, string> getSQLAlias);
33+
3234
/// <summary>
3335
/// Given a query alias and a property path, return the qualified column name
3436
/// </summary>
@@ -40,4 +42,4 @@ public interface IPropertyMapping
4042
/// <summary> Given a property path, return the corresponding column name(s).</summary>
4143
string[] ToColumns(string propertyName);
4244
}
43-
}
45+
}

src/NHibernate/Persister/Entity/JoinedSubclassEntityPersister.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,11 +504,6 @@ protected override void AddDiscriminatorToSelect(SelectFragment select, string n
504504
}
505505
}
506506

507-
public override int GetSubclassPropertyTableNumber(string propertyPath)
508-
{
509-
return 0;
510-
}
511-
512507
private CaseFragment DiscriminatorFragment(string alias)
513508
{
514509
CaseFragment cases = Factory.Dialect.CreateCaseFragment();

0 commit comments

Comments
 (0)