NHibernate Pitfalls: SQL Queries and Parameter Prefix
This is part of a series of posts about NHibernate Pitfalls. See the entire collection here.
When you execute an SQL query with NHibernate with named parameters, you would perhaps expect them to be prefixed with a symbol specific to the current DB you are accessing, for example, @ for SQL Server and : for Oracle; that is not the case. NHibernate requires that you always use it’s DB-neutral parameter prefix, :, the same that you use for HQL queries:
1: //for SQL queries
2: session.CreateSQLQuery("SELECT * FROM [Order] WHERE Id = :id").SetParameter("id", 1).List();
3: //for HQL queries
4: session.CreateQuery("from Order where id = :id").SetParameter("id", 1).List();