adlerus
adlerus

Reputation: 157

NHibernate QueryOver for superclass only

I am fighting right now with NHibernate and Table-per-class inheritance.

I have one base class (let's call it Base) and 10 derived classes. Sometimes I just want to make a query on Base class without left outer joins on subclasses.

var query = dao.CurrentSession.QueryOver<Base>()
   .JoinQueryOver(b => b.Property)
   .Where(p => p.FirstName == "Max")
   .Select(a => a.Id).Take(10);

What I get is a lot of "left outer joins" in sql query which I don't really need and it also slows down the performance of the query.

Is it somehow possible to get rid of the polymorphism in this case? Is there any way to change the inheritance model and derive Base class from some other class that won't be in the hierarchy?

Upvotes: 4

Views: 630

Answers (1)

Sardonic
Sardonic

Reputation: 126

In your Base mapping file, set the following:

polymorphism=”explicit”

Upvotes: 1

Related Questions