views:

28

answers:

2

Hi all,

I have a table that references many items. In the general view, I don't want to load all these references, for obvious performance reasons, but in the global view, I would like to load the same table, with all the references. I tried making two classes mapped on the same table, but it loads the two classes when loading the table, so it doesn't help.

Anybody did that before ?

A: 

References are loaded lazily by default (i.e. they won't be loaded unless they are actually used).

My suggestion is that you create a single class.

In any case, if you want to load only some properties, you can do so with a query.

Diego Mijelshon
Thanks for that, but it won't be enough...I just found a solution, a bit dirty, but it works, 3 classes. 1 base class, one extending the base one, and one "fake" extending class for Hibernate. Otherwise loading the base class loaded the extended class as well...
gougoul
That's the wrong way to use NH and it will cause other problems down the road... but it's your call.
Diego Mijelshon
A: 

Sounds to me like you're using Nhibernate for both domain model and querying/reporting.

I'd go about it the other way around - use Nhibernate for the domain model (the complex objects with references and logic in them) and your favorite data access for displaying the data. You can go with linq, datasets, ... That will give you the flexibility to query just the things you require. You can even use fluent nhibernate to auto map with conventions to some specialized view. Lots of flexibility that way...

jl

related questions