I’m working on a C# project using NHibernate, I use fluant-nhibernate with autoMapping :
FluentConfiguration configuration = Fluently.Configure()
.Database(databaseConfig)
.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Entity>(mappingConfiguration).Conventions.Add<GeometryTypeConvention>()));
I have a classes with IGeometry properties, I have configured automapping with a self Convention type :
public class GeometryTypeConvention : IUserTypeConvention
{
public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
{
criteria.Expect(p => p.Property.PropertyType == typeof (IGeometry));
}
public void Apply(IPropertyInstance instance)
{
instance.CustomType(typeof(MsSql2008GeometryType));
}
}
When I update the schema, the database is created but all Geometry properties in classes are set as TINYINT columns.
I’ve seen almost the same problem on http://www.klopfenstein.net/lorenz.aspx/null-geometry-values-in-nhibernate-spatial-for-mssql2008, but the file MsSql2008GeometryType.cs I use is correct.
I had the same problem, and I solved it this way (using geography instead of geometry, but it’s very similar):
First (this step is optional), and because I was required to work with WGS84 coordinates, I created the following type:
Then I created a convention somehow similar to yours, but with the “CustomSqlType” method specified:
Afterwards the schema generation should work without any issue.