Hello! I have the following XML (.hbm):
<property name="Geometry" column="the_geom">
<type name="NHibernate.Spatial.Type.GeometryType,NHibernate.Spatial">
<param name="subtype">MULTIPOLYGON</param>
<param name="srid">-1</param>
</type>
</property>
It´s using Nhibernate Spatial type... How can I map that property using ClassMap (Fluent Nhibernate) ?
Thanks
From stackoverflow
-
Well, I've not used NHibernate Spatial, but I browsed through the code and it looks like
GeometryTypeinherits 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
paramelements 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
WithTextfunctionality, you'll have to add an extension forXmlElementlike 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; } }Martin : When trying to use your code with Fluent NHibernate 1.0 I'm unable to find the AddAlteration function within the PropertyPart type. Is your code working with version 1.0 of Fluent NHibernate?Stuart Childs : No, this no longer works. In fact, WithAtt was removed not long after I made this post, if memory serves. You can still set the custom type with Map(x => ...).CustomType(), but I don't think you'll be able to get the param attribute/elements in there. I'd suggest posting to the FNH group at: http://groups.google.com/group/fluent-nhibernate
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.