Panache
Panache

Reputation: 289

Real world complex example of Nhibernate

The project on which i am working has a very complex business and data logic. I have around 90 tables and 250 stored procedures in my database.

I have seen very basic samples on Nhibernate through which the operations are performed on database.

I just want to know if we have a huge complex logic then how can we use nhibernate.

Also currently in some scenarios I handle the business logic at stored procedure level so if there is a slight change just making some changes in stored procedure sets things right for me. But if i am using Nhibernate how can i work with stored procedures and create complex situations work for me.

Can i get sample code in C# which uses nhibernate and contains complex real world scenarios.

Upvotes: 0

Views: 1312

Answers (2)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038770

An ORM such as NHibernate's primary goal is to abstract database access from the application and render it database agnostic. Having business logic inside stored procedure means that using an ORM will not bring any value whatsoever. Using plain ADO.NET would be more straightforward and beneficial. IMHO using NHibernate to call plain SQL or stored procedures is useless. You are just putting an additional layer to your application that wouldn't bring any value.

However if you move the business logic away from the database and have a nice object model an ORM could be really helpful to map this model to database tables.

Upvotes: 3

David Andres
David Andres

Reputation: 31781

Not only can stored procedures be called through NHibernate, but the ORM enables you to call these procedures in such a way that their result sets are converted automatically to specific entity types.

See http://softwaredevscott.spaces.live.com/blog/cns!1A9E939F7373F3B7!241.entry for an example. Specifically, you need to use the <sql-query> element of NHibernate's mapping files to set up the name, input parameters, and return type for your stored procedure. You can then refer to this stored procedure in code by the name you've provided.

I don't believe you can call stored procedures nakedly. They have to be given a name somewhere within the NHibernate mapping files.

As for complexity, I am completely on board with the challenges you're facing. I'm giving NHibernate a test run in my own projects to measure its performance and how much it boxes you in when you need flexibility. So far, I haven't had any issues.

Upvotes: 1

Related Questions