nhibernate - NHibernate 的枚举

标签 nhibernate

使用 NHibernate 存储枚举的推荐方法是什么?

换句话说,我应该在模型的属性中使用枚举类型吗?它的ID(整数)?还是一个字符串?

我想从 Fluent NHibernate 的角度来了解。

最佳答案

我们最近在工作中不得不处理这个问题。

我们正在使用 FluentNhibernate 并为此创建了一个约定:

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

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

然后你就可以映射你的属性(property)了

Map(x => x.Enum);

在数据库中,该字段是一个整数

关于nhibernate - NHibernate 的枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2788344/

相关文章:

c# - session 已关闭对象名称 : 'ISession' . 在 NHibernate.Impl.AbstractSessionImpl.ErrorIfClosed() - 如何阻止 session 过早关闭

c# - NHibernate 无状态插入行为

NHibernate QueryOver SQLFunction in where 子句

c# - 使用 Moq 模拟 NHibernate ISession

c# - 如何在 NHibernate 中映射多对多对多的三元关系?

asp.net-mvc - 什么会导致 NHibernate 的 Save 方法无提示地失败?

nhibernate - 流畅的 NHibernate : How to create one-to-one bidirectional mapping?

database - 如何使用 NHibernate 的 QueryOver 做到这一点?

c# - NHibernate QueryOver - 日期比较表达式

c# - 无法加载文件或程序集 'Newtonsoft.Json'