tags:

views:

57

answers:

3

I get a Antlr.Runtime.NoViableAltException thrown when trying to run the following query in NHibernate.

IQuery query = session.CreateQuery("from <table> where 1 in (select <column>.STIntersects(geography::STGeomFromText('POINT(:longitude :latitude)', 4326)))");

I'm setting longitude and latitude in setQuery.

my assumption is the :: in calling geography::STGeomFromText... because it's thinking it's a query parameter. Is there a way to escape the :?

This query works in my SQL Manager Studio.

Thanks!

+1  A: 

Does NHIbernate support the STIntersects method ?

What you could do, is let NHibernate execute a (native) SQL query, like this:

ISQLQuery query = session.CreateSQLQuery ("your sql statement goes here");
query.AddEntity (typeof(TheEntityTypeThatYouWant));

var result = query.List<TheEntityTypeThatYouWant>();
Frederik Gheysels
Good suggestion. I forgot to mention I tried that too. Those darn semi-colons!
Erix
A: 

Just to share what I ended up doing was taking the ADO connection out of the NHibernate session, performing a SqlCommand directly and manually built my Model objects from the results. It sucks, but it works. The connection still managed by NHibernate correctly.

Erix