Hi, I'm going through an application and replacing the raw SQL queries with Hibernate syntax. As a first step, I'm working on having the SQL return Hibernate Entities. For example, I'm replacing this:
SELECT * FROM Office
with this:
NHibernateSession.CreateSQLQuery("SELECT * FROM Office").AddEntity(GetType(Office)).list()
and then using the returned Office objects. However, I can't figure out how to get entities back from more complicated SQL queries. I've run into the below SQL statement. It selects all from Office, but also returns a derived column called "Distance" that is calculated using a SQL function called "getDistance".
SELECT *, db.getDistance(:lat, :lng, Latitude, Longitude) AS Distance FROM Office
Does anyone know how I could have entities return from this? If I use this:
NHibernateSession.CreateSQLQuery(sql).AddEntity(GetType(Office)).list()
it compiles and runs, but it seems to drop the Distance field (as expected). I've tried using .AddScalar() for the "Distance" column, but I can't figure out the structure of the returned List. Does anyone have any ideas? Thanks.
|