枚举解析似乎不适用于 Fluent NHibernate
我有一个带有名为 Salutation 的枚举的数据访问类:
public enum Salutation
{
Unknown = 0,
Dame = 1,
etc
Mr = 5,
etc
}
我正在使用 NHibernate 保留该类,直到今天早上我还在使用 .hbm.xml 文件进行映射。但是,我现在已改用 Fluent NHibernate,但加载该类的实例失败(例如):
[HibernateException: Can't Parse 5 as Salutation]
如您所见,5 应该可以解析为 Salutation(假设5是一个int,从错误消息中无法看出)。
有人知道这是怎么回事吗?
谢谢
大卫
I have a data access class with an Enum called Salutation:
public enum Salutation
{
Unknown = 0,
Dame = 1,
etc
Mr = 5,
etc
}
I am peristing the class with NHibernate, and up until this morning I was using .hbm.xml files for mapping. However, I've now switched to using Fluent NHibernate, but loading instances of the class fails with (for example):
[HibernateException: Can't Parse 5 as Salutation]
As you can see, 5 should be parseable as a Salutation (assuming 5 is an int, it's not possible to tell from the error message).
Anyone know what's going on here?
Thanks
David
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这比我想象的要容易得多。
This is much easier than I thought.
另一个选项是使用 EnumConvention:
要使用此 enumconvention:
在映射文件中,
Another option is using, EnumConvention:
To use this enumconvention:
And in mapping file,
由于最受接受的答案仍然因相同的错误而失败,这里是我的解决方案:
Since the most accepted answer does still fail with same error, here my solution: