I Have a entity with a property referencing other entity (ReferenceEntity in examples).
With HQL i can do this:
select e.ReferenceEntity from Entity e where e.Id = :entityId
NHibernate will give me the ReferenceEntity instance without lazy.
With query over im trying do this:
Session.QueryOver<Entity>()
.Where(e => e.Id == entityId)
.Select(e => e.ReferenceEntity)
.SingleOrDefault<ReferenceEntity>()
With QueryOver Nhibernate is giving me the ReferenceEntity but lazy.
I wanna get ReferenceEntity with eager loading using queryover like i do with hql.
Thanks
Best Answer
Suggestion #1
You could do a little bit of LINQ manipulation after you execute the query to grab the data you want.
It's simple and gets the job done.
In my test, it resulted in a single query. Here's the output:
Suggestion #2
Another approach would be to use an EXISTS subquery, which would be slightly more complex, but would return the right result the first time without any need for post-database manipulation:
Tested - results in single query: