11using System ;
22using System . Collections . Specialized ;
33using System . Linq ;
4+ using System . Linq . Expressions ;
45using NHibernate . Engine ;
56using NHibernate . Linq . Clauses ;
67using NHibernate . Linq . Visitors ;
8+ using NHibernate . Util ;
79using Remotion . Linq ;
810using Remotion . Linq . Clauses ;
911
1012namespace NHibernate . Linq . ReWriters
1113{
1214 internal interface IIsEntityDecider
1315 {
14- bool IsEntity ( System . Type type ) ;
15- bool IsIdentifier ( System . Type type , string propertyName ) ;
16+ bool IsEntity ( MemberExpression expression , out bool isIdentifier ) ;
1617 }
1718
1819 public class AddJoinsReWriter : NhQueryModelVisitorBase , IIsEntityDecider
@@ -77,11 +78,15 @@ public override void VisitJoinClause(JoinClause joinClause, QueryModel queryMode
7778 _currentJoin = null ;
7879 }
7980
81+ // Since v5.3
82+ [ Obsolete ( "This method has no usages and will be removed in a future version" ) ]
8083 public bool IsEntity ( System . Type type )
8184 {
8285 return _sessionFactory . GetImplementors ( type . FullName ) . Any ( ) ;
8386 }
8487
88+ // Since v5.3
89+ [ Obsolete ( "This method has no usages and will be removed in a future version" ) ]
8590 public bool IsIdentifier ( System . Type type , string propertyName )
8691 {
8792 var metadata = _sessionFactory . GetClassMetadata ( type ) ;
@@ -99,5 +104,14 @@ private void AddJoin(QueryModel queryModel, NhJoinClause joinClause)
99104
100105 queryModel . BodyClauses . Add ( joinClause ) ;
101106 }
107+
108+ bool IIsEntityDecider . IsEntity ( MemberExpression expression , out bool isIdentifier )
109+ {
110+ isIdentifier =
111+ ExpressionsHelper . TryGetMappedType ( _sessionFactory , expression , out var mappedType , out var entityPersister , out _ , out var memberPath )
112+ && entityPersister ? . IdentifierPropertyName == memberPath ;
113+
114+ return mappedType ? . IsEntityType == true ;
115+ }
102116 }
103117}
0 commit comments