1

I am new in implement Nhibernete.

If i use XML documents (.hbm.xml files) in Nhibernete, i enable/disable lazy loading in that xml.

Is there any way in Nhibernete where i can set lazy loading at run time?

1 Answer 1

2

I would suggest you not to define lazy loading/eager loading in your hbm file.

You can control everything using QueryOver

Lazy loading:

var order = Session.QueryOver<Domain.Order>()
    .Where(x => x.id == 12)
    .SingleOrDefault();

Eager loading:

Domain.OrderLine orderLine = null;

var order = Session.QueryOver<Domain.Order>()
    .Where(x => x.id == 12)
    .Fetch(x => x.OrderLines).Eager
        .JoinAlias(x => x.OrderLines, () => orderLine, JoinType.LeftOuterJoin)
    .SingleOrDefault();

or

var order = Session.QueryOver<Domain.Order>()
    .Where(x => x.id == 12)
        .Inner.JoinAlias(x => x.OrderLines, () => orderLine)
        .SingleOrDefault();

I would suggest you to read this interesting article.

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

Comments

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.