Well, I've not used NHibernate Spatial, but I browsed through the code and it looks like GeometryType
inherits from IUserType so you should be able to use it with .CustomTypeIs<>
For example:
Map(x => x.Geometry, "the_geom").CustomTypeIs<GeometryType>();
Unless it happens automagically, that probably won't get you your param
elements though. I'm not sure of a truly nice way to do this but you can always add an XML alteration like so:
Map(x => x.Geometry, "the_geom").AddAlteration(p => p.AddElement("type")
.WithAtt("name", "NHibernate.Spatial.Type.GeometryType,NHibernate.Spatial")
.AddElement("param")
.WithAtt("name", "subtype")
.WithText("MULTIPOLYGON")
.ParentNode
.AddElement("param")
.WithAtt("name", "srid")
.WithText("-1")
);
Note that to get the WithText
functionality, you'll have to add an extension for XmlElement
like so (WithAtt and AddElement are extensions in the FluentNHibernate.Mapping namespace):
public static class XmlExtensions
{
public static XmlElement WithText(this XmlElement element, string text)
{
element.InnerText = text;
return element;
}
}
If you build Fluent from source, there is now support for filters. You use them like this:
First create a class inheriting from FluentNHibernate.Mapping.FilterDefinition
:
using FluentNHibernate.Mapping;
namespace PonyApp.FluentFilters
{
public class PonyConditionFilter : FilterDefinition
{
public PonyConditionFilter()
{
WithName("PonyConditionFilter")
.AddParameter("condition",NHibernate.NHibernateUtil.String);
}
}
}
In your ClassMap for your class, use the ApplyFilter method:
namespace PonyApp.Entities.Mappings
{
public class PonyMap : ClassMap<Pony>
{
public PonyMap()
{
Id(x => x.Id);
Map(x => x.PonyName);
Map(x => x.PonyColor);
Map(x => x.PonyCondition);
ApplyFilter<PonyConditionFilter>("PonyCondition = :condition");
}
}
}
Then add the filter to your fluent config:
Fluently.Configure()
.Mappings(m => m.FluentMappings.Add(typeof(PonyConditionFilter)))
//blah blah bunches of other important stuff left out
.BuildSessionFactory();
Then you can turn it on and off just as you would with vanilla NHibernate:
session.EnableFilter("PonyConditionFilter").SetParameter("condition","Wonderful");
Best Answer
SelectBeforeUpdate()
in yourClassMap
.