Help with QueryOver and WhereExists

后端 未结 1 1130
小蘑菇
小蘑菇 2021-02-07 22:58

I have a problem. I have Persons and Cats. Each Person has some Cats (there is a foreign key in Cats that points to the primary key in Persons). Each Cat has an Age. I want to s

1条回答
  •  眼角桃花
    2021-02-07 23:48

    Example taken from this page and adapted (tested with my own classes):

    The trick seems to be using an alias.

    Person personAlias = null;
    
    IList persons = 
            session.QueryOver(() => personAlias).WithSubquery
              .WhereExists(QueryOver.Of()
                 .Where(c => c.Age > 5)
                 .And(c => c.Owner.Id == personAlias.Id)
                 .Select(c => c.Owner))
              .List();
    

    0 讨论(0)
提交回复
热议问题