2

How can I get same result with NHibernate QueryOver when using entity framework linq like this.

var result = items
   .include("subEntity1")
   .include("subEntity2")
   .include("subEntity3")
   .where(...).skip(x).take(y); 

1 Answer 1

3

A syntax with QueryOver could look like this:

var query = session.QueryOver<MyEntity>()
    // force the collection inclusion
    .Fetch(x => x.Collection1).Eager
    .Fetch(x => x.Collection2).Eager
    ...
    // force the relations inclusion
    .Fetch(x => x.SubEntity1).Eager
    .Fetch(x => x.SubEntity2).Eager
    ...
    // paging
    .Skip(x)
    .Take(y);

var list = query
     .List<MyEntity>();

Sources:

Sign up to request clarification or add additional context in comments.

2 Comments

I try this one but I'm getting duplicate entity in the result
Yes, that's the impact of the Fetch - collection. It always results in carthesian product. The appropriate way is in fact to do NOT Fetch. Change your mapping to a use batch-size, which will end in more then 1 query, but still very efficient. Please, check stackoverflow.com/a/20970816/1679310 or stackoverflow.com/a/19287008/1679310

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.