Skip to content

How to correctly make join by IQueryable with NHibernate #2478

Closed
@RockNHawk

Description

@RockNHawk

Hi,

I have searched may document about how to correctly make join by IQueryable with NHibernate, but sill cant make it work.

I have tried join like this:

var queryableLinq = (from user in _session3.Query<AppUserPartIndex>()
	join cii in _session3.Query<ContentItemIndex>() on user.DocumentId equals cii.DocumentId 
	where userIds.Contains(user.UserId) && cii.Published == true
	select user);
				
var items = queryableLinq.ToList();
Console.WriteLine(items);

but throws Path expected for join SemanticException.

NHibernate.Hql.Ast.ANTLR.SemanticException: Path expected for join! [
	.......
   at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.CreateFromJoinElement(IASTNode path, IASTNode alias, Int32 joinType, IASTNode fetchNode, IASTNode propertyFetch, IASTNode with)
   at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.joinElement()
   at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.fromElement()
	.....
   at NHibernate.Hql.Ast.ANTLR.HqlSqlTranslator.Translate()
   at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Analyze(String collectionRole)
	.....

Or add an statement into like this:

var queryableLinq = (from user in _session3.Query<AppUserPartIndex>()
	join cii in _session3.Query<ContentItemIndex>() on user.DocumentId equals cii.DocumentId into alias
	from a in alias
	where userIds.Contains(user.UserId) && a.Published == true
	select user);

but throws The method or operation is not implemented NotImplementedException

System.NotImplementedException: The method or operation is not implemented.
   at NHibernate.Linq.Visitors.QueryModelVisitor.VisitGroupJoinClause(GroupJoinClause groupJoinClause, QueryModel queryModel, Int32 index)
   at Remotion.Linq.Clauses.GroupJoinClause.Accept(IQueryModelVisitor visitor, QueryModel queryModel, Int32 index)
   at Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection`1 bodyClauses, QueryModel queryModel)
   at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
   at NHibernate.Linq.Visitors.QueryModelVisitor.Visit()
   at NHibernate.Linq.Visitors.QueryModelVisitor.GenerateHqlQuery(QueryModel queryModel, VisitorParameters parameters, Boolean root, Nullable`1 rootReturnType)
   at NHibernate.Linq.NhLinqExpression.Translate(ISessionFactoryImplementor sessionFactory, Boolean filter)
	.....

Or split join statement to two IQueryable like this:

var queryableLinq = (
	from user in _session3.Query<AppUserPartIndex>()
	from cii in _session3.Query<ContentItemIndex>()
	where user.DocumentId == cii.DocumentId && userIds.Contains(user.UserId) &&
		  cii.Published == true
	select user);

var items = queryableLinq.ToList();
Console.WriteLine(items);

but also throws Path expected for join SemanticException.

I use NHibernate 5.3.2, how can I do join with IQueryable ? Thanks!

[assembly: AssemblyFileVersion("5.3.2.0")]
[assembly: AssemblyInformationalVersion("5.3.2+ed36de0de7ca8bcfb512b4878cb50e7dcd5b54b9")]

see also:

#864

#2037

https://stackoverflow.com/questions/13394759/how-to-use-join-with-multiple-conditions-in-linq-to-nhibernate

https://stackoverflow.com/questions/14425749/how-linq-to-nhibernate-by-join-and-separate-where-in-query

https://groups.google.com/forum/#!searchin/nhusers/query$20join%7Csort:date

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions