-
Notifications
You must be signed in to change notification settings - Fork 934
Support to join not associated entities in Criteria (aka Entity Join) #1545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a49c739
Support to join not associated entities in Criteria API (aka Entity J…
bahusoid fffd3c5
Interface changes
bahusoid 817d85b
clean up
bahusoid 1f77db9
JoinFragment: explicitly remove " and " clause
bahusoid b75d6a5
async regen
bahusoid 5e089e6
test cleanup
bahusoid 8ac4b7b
Simplified ISupportEntityJoinQueryOver interface
bahusoid 3f6bb94
Fixed exception message, added one more Criteria extension
bahusoid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
546 changes: 546 additions & 0 deletions
546
src/NHibernate.Test/Async/Criteria/EntityJoinCriteriaTest.cs
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Linq.Expressions; | ||
using NHibernate.SqlCommand; | ||
|
||
namespace NHibernate.Criterion | ||
{ | ||
// 6.0 TODO: merge into IQueryOver<TRoot,TSubType>. | ||
public interface ISupportEntityJoinQueryOver<TRoot> | ||
{ | ||
IQueryOver<TRoot, U> JoinEntityQueryOver<U>(Expression<Func<U>> alias, ICriterion withClause, JoinType joinType, string entityName); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Linq.Expressions; | ||
using NHibernate.Criterion; | ||
using NHibernate.Impl; | ||
using NHibernate.SqlCommand; | ||
|
||
namespace NHibernate | ||
{ | ||
public static class EntityJoinExtensions | ||
{ | ||
public static TThis JoinEntityAlias<TThis, TEntity>(this TThis queryOver, Expression<Func<TEntity>> alias, ICriterion withClause, JoinType joinType = JoinType.InnerJoin, string entityName = null) where TThis : IQueryOver | ||
{ | ||
CreateEntityCriteria(queryOver.UnderlyingCriteria, alias, withClause, joinType, entityName); | ||
return queryOver; | ||
} | ||
|
||
public static TThis JoinEntityAlias<TThis, TEntity>(this TThis queryOver, Expression<Func<TEntity>> alias, Expression<Func<bool>> withClause, JoinType joinType = JoinType.InnerJoin, string entityName = null) where TThis : IQueryOver | ||
{ | ||
return JoinEntityAlias(queryOver, alias, Restrictions.Where(withClause), joinType, entityName); | ||
} | ||
|
||
public static IQueryOver<TRoot, TEntity> JoinEntityQueryOver<TRoot, TEntity>(this IQueryOver<TRoot> queryOver, Expression<Func<TEntity>> alias, Expression<Func<bool>> withClause, JoinType joinType = JoinType.InnerJoin, string entityName = null) | ||
{ | ||
return JoinEntityQueryOver(queryOver, alias, Restrictions.Where(withClause), joinType, entityName); | ||
} | ||
|
||
public static IQueryOver<TRoot, TEntity> JoinEntityQueryOver<TRoot, TEntity>(this IQueryOver<TRoot> queryOver, Expression<Func<TEntity>> alias, ICriterion withClause, JoinType joinType = JoinType.InnerJoin, string entityName = null) | ||
{ | ||
var q = CastOrThrow<ISupportEntityJoinQueryOver<TRoot>>(queryOver); | ||
return q.JoinEntityQueryOver(alias, withClause, joinType, entityName); | ||
} | ||
|
||
public static ICriteria CreateEntityAlias(this ICriteria criteria, string alias, ICriterion withClause, JoinType joinType, string entityName) | ||
{ | ||
CreateEntityCriteria(criteria, alias, withClause, joinType, entityName); | ||
return criteria; | ||
} | ||
|
||
public static ICriteria CreateEntityCriteria(this ICriteria criteria, string alias, ICriterion withClause, JoinType joinType = JoinType.InnerJoin, string entityName = null) | ||
{ | ||
var c = CastOrThrow<ISupportEntityJoinCriteria>(criteria); | ||
return c.CreateEntityCriteria(alias, withClause, joinType, entityName); | ||
} | ||
|
||
public static ICriteria CreateEntityCriteria<U>(this ICriteria criteria, Expression<Func<U>> alias, ICriterion withClause, JoinType joinType = JoinType.InnerJoin, string entityName = null) | ||
{ | ||
return CreateEntityCriteria(criteria, ExpressionProcessor.FindMemberExpression(alias.Body), withClause, joinType, entityName ?? typeof(U).FullName); | ||
} | ||
|
||
private static T CastOrThrow<T>(object obj) where T : class | ||
{ | ||
return obj as T | ||
?? throw new ArgumentException($"{obj.GetType().FullName} requires to implement {nameof(T)} interface to support explicit entity joins."); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using NHibernate.Criterion; | ||
using NHibernate.SqlCommand; | ||
|
||
namespace NHibernate.Impl | ||
{ | ||
// 6.0 TODO: merge into 'ICriteria'. | ||
public interface ISupportEntityJoinCriteria | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add a " 6.0 TODO: merge with ICriteria". Is there a reason for not aiming at this? |
||
{ | ||
ICriteria CreateEntityCriteria(string alias, ICriterion withClause, JoinType joinType, string entityName); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not seen the reason for implementing this interface on this class rather than on
QueryOver<TRoot>
. Why this choice?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe because that is the way it looks to be done for other similar cases. But then,
ISupportEntityJoinQueryOver<TRoot>
"6.0 todo" should be "merge inIQueryOver<TRoot, TSubType>
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I've just put it next to existing
JoinAlias
/JoinQueryOver
methods. Looks more natural to have them in the same place.