I got a follow up question to this question.
I use Silverlight and WCF, where lazyloading isn’t an option. How can i ignore a HasMany relation programmatically in some cases improve performance? (I just want the Foo’s without the related Bars).
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Basically, what you’re trying to do is not possible, be it NHibernate or Fluent. You can’t have mapping saying “sometimes load, sometimes not”. Setting
Not.LazyLoad()is pretty much show stopper – NHibernate will load collection always, entirely.Those kind of optimization (sometimes load, sometimes not) are better suited to be handled at DAO part of your model. For example, you could have your
FooDaoclass looking like this:With standard mapping (as in, not using
Not.LazyLoad()), first method will still return Foos with Bars collection fully set (we just need to tell NHibernate to load them now, before we return). However, second one tho will returnFooobjects only. No singleBarwill be loaded. Instead, NHibernate will generate proxy object in place of Bars collection for everyFoo.Your WCF service can use such DAO object internally. Naturally, you can have similar methods to load single Foo.
Conclusion is simple; mappings alone won’t help you with your problem. You need to do some extra coding work, but it definitely is possible.