- In the NHibernate section of your configuration file add the following entry:
Replace SomeSpatialDialect by the spatial dialect to be used (eg. MsSql2008SpatialDialect.) and SomeSpatialAssembly by the assembly name where it is located (eg. NHibernate.Spatial.MsSql2008)
Schema Generation Configuration:
Then you can use a SchemaExport object or the hibernate.hbm2ddl.auto configuration property for schema generation.
Metadata Mappings Configuration:
There are two classes available for metadata mapping in the NHibernate.Spatial.Metadata namespace: GeometryColumn and SpatialReferenceSystem. You can add them selectively:
Then you can use them as normal mapped classes. For example, you could execute the following HQL query:
WARNING: DO NOT add metadata class mappings when using the SchemaExport utility. You could lose all contents of metadata tables.
- In the XML mappings file, map all properties as usual but for geometry columns use the following entry:
- Optionally, for schema generation and default values setting, you can use type parameters. The available parameters are srid and subtype. For example:
- In the mapped class, declare the corresponding property:
NOTE: Type parameters (see NHibernate mapping above) are not supported in ActiveRecord.
ActiveWriter is a tool to visually model entities and relationships, and generate ActiveRecord classes or NHibernate mapping files. Since Preview 3, it supports custom types, so we can use the GeometryType / IGeometry pair..
- Drag & drop a MsSqlSpatial table from Server Explorer/Data connections.
- In the model, select "the_geom" property.
- In the properties window, enter the following values:
|Custom Column Type
|Custom Member Type
NOTE: Type parameters (see NHibernate mapping above) are not supported in ActiveRecord, so it is in ActiveWriter.