This is a mirror of official site: http://jasper-net.blogspot.com/

NHibernate Pitfalls: SQL Queries and Parameter Prefix

| Wednesday, January 11, 2012
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:

//for SQL queries
session.CreateSQLQuery("SELECT * FROM [Order] WHERE Id = :id").SetParameter("id", 1).List();
//for HQL queries
session.CreateQuery("from Order where id = :id").SetParameter("id", 1).List();

Read more: Development With A Dot
QR: nhibernate-pitfalls-sql-queries-and-parameter-prefix.aspx

Posted via email from Jasper-net

0 comments: