如何使用流畅的 NHibernate 将枚举映射为 int 值? [英] How do you map an enum as an int value with fluent NHibernate?

查看:22
本文介绍了如何使用流畅的 NHibernate 将枚举映射为 int 值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题说明了一切,默认情况下是将其映射为 string,但我需要将其映射为 int.

Question says it all really, the default is for it to map as a string but I need it to map as an int.

我目前正在使用 PersistenceModel 来设置我的约定,如果这有什么不同的话.提前致谢.

I'm currently using PersistenceModel for setting my conventions if that makes any difference. Thanks in advance.

更新发现从主干获取最新版本的代码解决了我的问题.

Update Found that getting onto the latest version of the code from the trunk resolved my woes.

推荐答案

定义这个约定的方式以前有时会改变,现在是:

The way to define this convention changed sometimes ago, it's now :

public class EnumConvention : IUserTypeConvention
{
    public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
    {
        criteria.Expect(x => x.Property.PropertyType.IsEnum);
    }

    public void Apply(IPropertyInstance target)
    {
        target.CustomType(target.Property.PropertyType);
    }
}

这篇关于如何使用流畅的 NHibernate 将枚举映射为 int 值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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