Fuent NHIbernate two mappings on the same table, no discriminator
I have a table that references many items. In the general view, I don't want to load all these reference开发者_StackOverflow中文版s, 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 ?
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.
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...
精彩评论