title: combining sql server spatial and NHibernate with CreateSqlQuery
body: <p>I have not mapped geography table in sql server 2008, and I want to query it with a polygon instance in c# using nhibernate.
  <br>In the beggining I was trying to use sql server spatial directly but encountered this problem:
  <a href="https://stackoverflow.com/questions/238050/using-sql-server-2008-geography-types-with-nhibernates-createsqlquery">Using SQL Server 2008 Geography types with nHibernate&#39;s CreateSQLQuery</a>
  <p>My second try was this:</p>
  
  <pre><code>session.CreateSQLQuery("select [shape] from [table] where (:codeShape).STIntersects([shape]) = 1").SetParameter("codeShape", codeShape, NHibernateUtil.Custom(typeof(MsSql2008GeographyType)));
  </code></pre>
  
  <p>however this try also raise an exception:
  <br></p>
  
  <pre><code>Could not execute query [select [shape] from [table] where (?).STIntersects([shape]) = 1")] Name:codeShape - Value:POLYGON((30 40, ...))
  </code></pre>
  
  <p><p>and the inner exception is:<br></p>
  
  <pre><code>The specified input does not represent a valid geography instance.
  </code></pre>
  
  <p>That's despite codeShape.IsValid returns true.</p>
  
  <p>When I run this query directly in sql server I get the expected result.</p>
  
  <p>any ideas or solutions?</p>
  
  <p>Thanks.</p>