I have an existing asp.net webforms project that uses Microsoft's Enterprise DAAB for the DAL, I need to implement some extensive features, and I would like to use NHibernate to make things easier.
Is there any design patterns/architectures out there that allow a hybrid DAAB/NHibernate DAL ? is it a good idea ?
My thinking is: if I had a hybrid DAL I could still pass high traffic/un-dynamic queries through the DAAB side and save the overhead of the dynamic sql generation. But still have nhibernate for more complex queries.
Additionally what is the best way to setup NHibernate DAL/BLL for an asp.net webforms application ? I have read the tutorial on the NHibernate site and several others there doesn't seem to be a consensus on starting/ending the nhib session. I'm just looking for best practice example.
Thanks
One approach I've heard about is use nHibernate for when your interact with your domain model. Keep in mind nHibernate can call stored procedures so if you want to avoid the SQL Generation you can but I'd advise against.
If you have queries for reporting or displaying data that you don't want to create custom entities from then you could use DAAB, althought I would not recommend doign this if your going to create your entities.
As for best practice, I've found that creating the Session when you need it, and then store it in httpContext, you will close the session on every reqyuest.
The only other thing then is to specificly create and end a transaction which I would do in your service layer or application tier if your logic would span multiple services (I define a service not as a webservice but as a high level piece of code which shields your application from your domain layer).
A good starting point is from Billy McCafferty's article here: http://www.codeproject.com/KB/architecture/NHibernateBestPractices.aspx
There is a bug / limitation within his code check out my blog post if you use his method: http://jberke.blogspot.com/2008/10/nhibernate-transaction-session-mgmt.html