流利NHibernate的问题(ClassMap) [英] Fluent Nhibernate problem (ClassMap)

查看:219
本文介绍了流利NHibernate的问题(ClassMap)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的XML(.hbm):

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>



使用NHibernate空间类型...

如何汇入作业我可以映射特性使用ClassMap(流利NHibernate的)?

It´s using Nhibernate Spatial type... How can I map that property using ClassMap (Fluent Nhibernate) ?

感谢

推荐答案

好吧,我'已经不使用NHibernate的空间,但我通过代码浏览,它看起来像 GeometryType 从IUserType继承,所以你应该能够与使用它。 CustomTypeIs<>

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<>

例如:

Map(x => x.Geometry, "the_geom").CustomTypeIs<GeometryType>();



除非它自动的,这可能不会让你的参数虽然元素。我不知道一个真正好的办法做到这一点,但你总是可以添加一个XML改变,像这样:

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")
    );

请注意,要获得 WithText 的功能,你必须添加一个扩展的XmlElement 像这样(WithAtt和的addElement都在FluentNHibernate.Mapping命名空间扩展):

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;
    }
}

这篇关于流利NHibernate的问题(ClassMap)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆