@@ -8,6 +8,8 @@ namespace NHibernate
88{
99 public static class EntityJoinExtensions
1010 {
11+ #region QueryOver extensions
12+
1113 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
1214 {
1315 CreateEntityCriteria ( queryOver . UnderlyingCriteria , alias , withClause , joinType , entityName ) ;
@@ -30,13 +32,23 @@ public static IQueryOver<TRoot, TEntity> JoinEntityQueryOver<TRoot, TEntity>(thi
3032 return q . JoinEntityQueryOver ( alias , withClause , joinType , entityName ) ;
3133 }
3234
35+ #endregion QueryOver extensions
36+
37+ #region Criteria extensions
38+
3339 public static ICriteria CreateEntityAlias ( this ICriteria criteria , string alias , ICriterion withClause , JoinType joinType , string entityName )
3440 {
3541 CreateEntityCriteria ( criteria , alias , withClause , joinType , entityName ) ;
3642 return criteria ;
3743 }
44+
45+ public static ICriteria CreateEntityAlias < U > ( this ICriteria criteria , Expression < Func < U > > alias , ICriterion withClause , JoinType joinType = JoinType . InnerJoin , string entityName = null )
46+ {
47+ CreateEntityCriteria ( criteria , alias , withClause , joinType , entityName ) ;
48+ return criteria ;
49+ }
3850
39- public static ICriteria CreateEntityCriteria ( this ICriteria criteria , string alias , ICriterion withClause , JoinType joinType = JoinType . InnerJoin , string entityName = null )
51+ public static ICriteria CreateEntityCriteria ( this ICriteria criteria , string alias , ICriterion withClause , JoinType joinType , string entityName )
4052 {
4153 var c = CastOrThrow < ISupportEntityJoinCriteria > ( criteria ) ;
4254 return c . CreateEntityCriteria ( alias , withClause , joinType , entityName ) ;
@@ -47,10 +59,12 @@ public static ICriteria CreateEntityCriteria<U>(this ICriteria criteria, Express
4759 return CreateEntityCriteria ( criteria , ExpressionProcessor . FindMemberExpression ( alias . Body ) , withClause , joinType , entityName ?? typeof ( U ) . FullName ) ;
4860 }
4961
62+ #endregion Criteria extensions
63+
5064 private static T CastOrThrow < T > ( object obj ) where T : class
5165 {
5266 return obj as T
53- ?? throw new ArgumentException ( $ "{ obj . GetType ( ) . FullName } requires to implement { nameof ( T ) } interface to support explicit entity joins.") ;
67+ ?? throw new ArgumentException ( $ "{ obj . GetType ( ) . FullName } requires to implement { typeof ( T ) . FullName } interface to support explicit entity joins.") ;
5468 }
5569 }
5670}
0 commit comments