views:

74

answers:

2

I've not yet found a clear answer to this and to clarify:

With nHibernate and SQL server are you expected to disregard or migrate your business logic stored in your stored procedures, views and triggers into HQL or application code?

+1  A: 

NHibernate is an O/R mapper which is very suited for applications that are build using a 'domain driven' methodology.
In such applications, the domain model is an expressive object oriented model of the business. This means that the 'model' contains all (or most of) the business logic.
In such cases, I see very little (if any) situations where you would put business logic into stored procedures.

Frederik Gheysels
This would explain a lot then. I have been tasked with writing an object "layer" on top of an existing database structure in which a lot of the logic is contained within existing database objects.
Neil Ramsbottom
A: 

Well, leaving aside all details: yes.

NH is an Object-relational mapper, and is intended to be used with an architectural style called 'Domain-Driven Design'. An important aspect of it is that it completely disregards the database for anything other than saving and loading data - this concept is called Persistence Ignorance, and its motto is: There is no database.

From this point of view, having business logic living in stored procedures or some other db object is not only discouraged, but it would clearly be a severe code smell.

If you follow the preferred Domain-Driven Design methodology, there will be just no opportunity to put business logic into the db - simply because there isn't any db around at the time of constructing your business layer...

Thomas Weller
I agree with this, but would add that NH has good support for stored procedures and very non-DDD databases, so you can benefit from using it even when your existing databases don't conform to the preferred style. We use NH for data access in apps that work with multiple databases, some built for DDD and NH, and one that is very old school.
Stuart Ellis