C# – Should I use nhibernate for a one row settings table

cnhibernateorm

I am using nhibernate in a quite big project.

The system has a settings table which has 10 columns and one row, there is always a row and it should not be deleted only modified.
Concurrency can be a problem as many clients can increment columns in the table like LastReceiptId.

I'm thinking, it can't be a good idea to use nhibernate to solve this.

With raw sql I can use a transaction and lock the table with for example: With (TABLOCKX, HOLDLOCK) while I select and update the LastReceiptId.

Do you have any reasons to use or not use nhibernate in a situation like this?

Best Answer

Your post gives me the (maybe false?) impression that you are questioning the use of NHibernate in full, because of a minor problem which cannot be perfectly solved by an ORM directly. Actually, in such a situation I would try to create a workaround for the minor problem (maybe I got you wrong, and that is what you already have in mind).

For the case you described, I am pretty sure some additional stored procedures can be utilized for solving your problem (assumed you are using a database system with full stored procedure support). For example, if you need custom INSERT operations with specific handling of IDs and/or locking, encapsulate the operation in a stored procedure and combine it with NHibernate like shown here. I am not an expert on NHibernate, but you will find more information on combining it with stored procedures on Stackoverflow.

Related Topic