Help with QueryOver and WhereExists

后端 未结 1 1127
小蘑菇
小蘑菇 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<Person> persons = 
            session.QueryOver<Person>(() => personAlias).WithSubquery
              .WhereExists(QueryOver.Of<Cat>()
                 .Where(c => c.Age > 5)
                 .And(c => c.Owner.Id == personAlias.Id)
                 .Select(c => c.Owner))
              .List<Person>();
    
    0 讨论(0)
提交回复
热议问题