views:

30

answers:

2

Hi All,

We are using NHibernate as our ORM for the project and we have only database read only feature. The application will not be updating,deleting or inserting any records into the database it will be just querying the database for records.

My question is which is the best method to query the database with NHibernate in the scenario explained above.

A: 

Since it is read only, you probably won't have much use for retrieving the query results as mapped objects. A result set type return value might be more useful. For that use session.createQuery and then query.list Each element of the list will be a object array. Each array element correponds to one select column.

bagheera
+1  A: 

Are you sure you really need an ORM?

Anyway, there are 3 common options to query database using NHibernate:

  1. HQL.
  2. Criteria API.
  3. Linq.

The easiest is 3, the most powerful is 1.

But I don't really understand the nature of your question as the query APIs in NHiebrnate are not muturally exclusive, but rather they add up each other.

So you can use any of them depending on the situation:

  • For dynamic queries - best is Criteria API.
  • For complex and never changing - HQL.
  • For quick and easy - Linq.
Dmytrii Nagirniak