如何使用 NHibernate 持久化枚举 [英] How to persist an enum using NHibernate

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

问题描述

有没有办法使用 NHibernate 将枚举持久化到数据库?即有一个包含枚举中每个值的代码和名称的表格.

Is there a way to persist an enum to the DB using NHibernate? That is have a table of both the code and the name of each value in the enum.

我想保留没有实体的枚举,但仍然具有从所有其他引用实体到枚举表的外键(枚举的 int 表示).

I want to keep the enum without an entity, but still have a foreign key (the int representation of the enum) from all other referencing entities to the enum's table.

推荐答案

你们为什么要把这个事情复杂化?真的很简单.

Why are you guys over complicating this? It is really simple.

映射如下:

<property name="OrganizationType"></property>

模型属性如下所示:

public virtual OrganizationTypes OrganizationType { get; set; }

枚举看起来像这样:

public enum OrganizationTypes
{
    NonProfit = 1,
    ForProfit = 2
}

NHibernate 会自动解决所有问题.为什么输入比你需要的更多????

NHibernate will automatically figure it all out. Why type more than you need????

这篇关于如何使用 NHibernate 持久化枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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