Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3278520
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:29:25+00:00 2026-05-17T19:29:25+00:00

I am trying to use Nhibernate with the Sql 2008 Geography type and am

  • 0

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.

First, the class I am trying to persist looks something like:

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;}
}

The mapping class looks like:

public class LocationLogMap : ClassMap<LocationLog>
{
   ImportType<GisSharpBlog.NetTopologySuite.Geometries.Point>();
   Id(x => x.Id);
   Map(x => x.TimeStamp).Generated.Insert();
   Map(x => x.Location);
}

In order to use the MsSql2008GeographyDialect with Fluent Nhibernate, I have created my own configuration class:

public class Sql2008Configuration
  : PersistenceConfiguration<Sql2008Configuration, MsSqlConnectionStringBuilder>
{
   public Sql2008Configuration()
   {
      Driver<SqlClientDriver>();
   }

   public static Sql2008Configuration MsSql2008
   {
      get { return new Sql2008Configuration().Dialect<MsSql2008GeographyDialect>(); }
   }
}

so I have configuration code like:

var configuration = Fluently.Configure()
  .Database(Sql2008Configuration.MsSql2008.ConnectionString(c => c.Is(connectionString)))
  .Mappings(m => m.FluentMappings
    .AddFromAssemblyOf<LocationLog>()
);

All of this to setup the fact that I am getting the following error when trying to persist the LocationLog type to the database:

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* )

I have read the following articles about how to configure and use the Nhibernate Spatial libraries:

  • http://nhibernate.info/doc/spatial/configuration-and-mapping.html
  • http://nhibernate.info/doc/spatial/sample-usage.html

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:29:26+00:00Added an answer on May 17, 2026 at 7:29 pm

    I am in the same boat, and thanks to your start I got it working (inserting and reading spatial data). For anyone else who is interested, firstly the GisSharpBlog.NetTopologySuite.Geometries.Point class is in NetTopologySuite.dll which is part of the nHibernate.Spatial download.

    Secondly, as per James point, make sure you set the SRID to 4326.

    And lastly, the map needs to look like this:

    Map(a => a.Location).CustomType(typeof(NHibernate.Spatial.Type.GeometryType));
    

    I am using Geography, but I read somewhere that using GeometryType may work and it does for me (I inserted some points and verified it in the database). I also read that its best to write SQL Query’s for Geography so that you can use the special SQL 2008 Spatial methods (as opposed to using Criteria).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to use nhibernate on sql-server compact edition for unit testing and having some
I am trying to use Nhibernate with Oracle using Microsoft's System.Data.OracleClient Nhibernate Configuration (Is
I am starting to use Fluent nHibernate on a project and am trying to
I'm running NHibernate and SQL Server CE I am trying to use GUIDs as
I'm trying to use NHibernate for data access, and I have 2 simple entities
Trying to use an excpetion class which could provide location reference for XML parsing,
While trying to use LINQ to SQL I encountered several problems. I have table
I am trying to do a MVC project where i want to use fluent
I am using Fluent NHibernate on a project that has an Oracle 10g database.
I am starting a new project using C# and ASP.NET 3.5 with SQL Server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.