title: NHibernate.Spatial and Sql 2008 Geography type - How to configure
body: <p>I am trying to use Nhibernate with the Sql 2008 Geography type and am having difficulty. I am using Fluent Nhibernate to configure which I am fairly new to so that may be the problem as well.</p>
  
  <p>First, the class I am trying to persist looks something like:</p>
  
  <pre><code>public class LocationLog : FluentNHibernate.Data.Entity
  {
     public virtual new int Id {get;set;}
     public virtual DateTime TimeStamp {get;set;}
     public virtual GisSharpBlog.NetTopologySuite.Geometries.Point Location {get;set;}
  }
  </code></pre>
  
  <p>The mapping class looks like:</p>
  
  <pre><code>public class LocationLogMap : ClassMap&lt;LocationLog&gt;
  {
     ImportType&lt;GisSharpBlog.NetTopologySuite.Geometries.Point&gt;();
     Id(x =&gt; x.Id);
     Map(x =&gt; x.TimeStamp).Generated.Insert();
     Map(x =&gt; x.Location);
  }
  </code></pre>
  
  <p>In order to use the MsSql2008GeographyDialect with Fluent Nhibernate, I have created my own configuration class:</p>
  
  <pre><code>public class Sql2008Configuration
    : PersistenceConfiguration&lt;Sql2008Configuration, MsSqlConnectionStringBuilder&gt;
  {
     public Sql2008Configuration()
     {
        Driver&lt;SqlClientDriver&gt;();
     }
  
     public static Sql2008Configuration MsSql2008
     {
        get { return new Sql2008Configuration().Dialect&lt;MsSql2008GeographyDialect&gt;(); }
     }
  }
  </code></pre>
  
  <p>so I have configuration code like:</p>
  
  <pre><code>var configuration = Fluently.Configure()
    .Database(Sql2008Configuration.MsSql2008.ConnectionString(c =&gt; c.Is(connectionString)))
    .Mappings(m =&gt; m.FluentMappings
      .AddFromAssemblyOf&lt;LocationLog&gt;()
  );
  </code></pre>
  
  <p>All of this to setup the fact that I am getting the following error when trying to persist the LocationLog type to the database:</p>
  
  <blockquote>
    <p>A .NET Framework error occurred during
    execution of user-defined routine or
    aggregate "geography": 
    System.ArgumentException: 24204: The
    spatial reference identifier (SRID) is
    not valid. The specified SRID must
    match one of the supported SRIDs
    displayed in the
    sys.spatial_reference_systems catalog
    view. System.ArgumentException:    at
    Microsoft.SqlServer.Types.SqlGeography.set_Srid(Int32
    value)   at
    Microsoft.SqlServer.Types.SqlGeography.Read(BinaryReader
    r)   at
    SqlGeography::.DeserializeValidate(IntPtr
    , Int32 , CClrLobContext* )</p>
  </blockquote>
  
  <p>I have read the following articles about how to configure and use the Nhibernate Spatial libraries:</p>
  
  <ul>
  <li><a href="http://nhibernate.info/doc/spatial/configuration-and-mapping.html" rel="nofollow noreferrer">http://nhibernate.info/doc/spatial/configuration-and-mapping.html</a></li>
  <li><a href="http://nhibernate.info/doc/spatial/sample-usage.html" rel="nofollow noreferrer">http://nhibernate.info/doc/spatial/sample-usage.html</a></li>
  </ul>
  
  <p>but neither seem to help. Anybody that has experience configuring Nhibernate to use the Spatial Geography types who could provide any insights would be greatly appreciated.</p>