Search code examples
nhibernateormprojection

Nhibernate SQL named queries and projection


I've mapped a class to a SQL Server table and use an SQL named query to retrieve some rows from it. Also I don't want all of the columns on certain pages (e.g. if it's a document, I want to display its full content on a "View Details" page only, while its title can be on a list and the "View Details" page.

If I don't select all of the columns of the table in question, I get an IndexOutOfRangeException on the columns that I've left out.

Is there a way to project only the columns I'm interested in on named queries or do I have to create extra POCOs for the different scopes of the application?

Regards, F.


Solution

  • You want NHibernate ad-hoc mapping.

    P.S.: Like the others have said, you should at least take a look at HQL, Criteria or NHibernate.Linq. And to easily handle the generated SQL, everyone uses the NHibernate Profiler.