开发者

unit of work and session per request in nhibernate and asp.net mvc

开发者 https://www.devze.com 2022-12-12 23:50 出处:网络
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 l

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 patter开发者_开发技巧n 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.


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


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号