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:
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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…