Question

I have been using the ncommon framework (http://code.google.com/p/ncommon/) with nhibernate and asp.net mvc. I really like the implementation of the unit of work pattern, but am having problems with lazy loading in my views. I am looking how to implement the session per request pattern with ncommon or look at another framework that will support:

  1. linq to nhibernate
  2. unit of work pattern
  3. session per request pattern to support lazy loading in views

Any tips greatly appreciated.

Was it helpful?

Solution

Take a look at SharpArchitecture.net for a great NHibernate based framework for MVC that I believe will fit your specifications.

OTHER TIPS

First of all if you are using your entities in your view model you are doing it wrong. I am sorry to break it to you but you can't really use your database model in your views. If I have for instance a Competition entity in the database I might end up with 3-4 CompetitionView based on what I need. Basically I load everything I might need eagerly and send just what is required for that specific view.

At first this seemed like more work to me than trying to solve it with NHibernate but in the end I found that I gain a tremendous amount of time on doing this straight away. There is also an open source project called AutoMapper that can transfer data between the various entities in your different models.

Hope this helps and that you don't despair on the best-practice!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top