NHibernate QueryOver to join unrelated entities

前端 未结 4 1525
我寻月下人不归
我寻月下人不归 2020-12-16 20:07

I have the following query working which gets the results I want:

int associatedId = 123;

MyObject alias = null;

var subQuery = QueryOver.Of

        
4条回答
  •  醉梦人生
    2020-12-16 21:00

    You can join onto unrelated entities with Linq in NHibernate 3+

    Funnily enough you use the join query expression element:

    from type1 in Repository.Query() 
    join type2 in Repository.Query() 
    on type1.Id equals type2.Id
    

    Note: Repository.Query is just returning an IQueryable Query from the session

    I'm hoping there is a solution for QueryOver as I don't always want to model two-way relationships in my domain but they are still useful for querying.

    Also, you can map a Access="noop" 2 way relationship using Criteria API without putting into your POCO classes:

    http://ayende.com/blog/4054/nhibernate-query-only-properties

提交回复
热议问题