将 EnumType 与 Fluent NHibernate 和 Automapping 结合使用
我正在研究一个使用 nhibernate 的项目,我有一个关于如何使用 FluentNhibernate 1.0.0.593 和 NHibernate 2.1.0.4000 最好地完成以下场景的问题。
我的表格如下所示:
DeviationLog:
Id uniqueidentifier
DeviationType uniqueidentifier
IncomingMessageId uniqueidentifier
DeviationType:
Id uniqueidentifier
DeviationTypeCategory uniqueidentifier
DeviationMessage nvarchar(255)
DeviationTypeCategory:
Id uniqueidentifier
DeviationTypeCategoryName nvarchar(255)
我目前正在使用带有约定的自动映射。
当我创建 Deviation 实例时,我希望能够执行以下操作:
var deviation = new Deviation{DeviationType=DeviationEnum.NoMatchMobileNumber};
现在据我所知,枚举仅支持整数类型,因此如果没有其他方法,这将无法工作。我正在考虑是否可以使用字典来实现这一点,例如 Dictionary
,而且我还怀疑我可能需要使用 UserTypeConvention
来实现这在某种程度上起作用了。
有人有经验可以分享吗?
I'm looking into a project using nhibernate and I have a question on how to best accomplish the following scenario, using FluentNhibernate 1.0.0.593, and NHibernate 2.1.0.4000
My tables look like this:
DeviationLog:
Id uniqueidentifier
DeviationType uniqueidentifier
IncomingMessageId uniqueidentifier
DeviationType:
Id uniqueidentifier
DeviationTypeCategory uniqueidentifier
DeviationMessage nvarchar(255)
DeviationTypeCategory:
Id uniqueidentifier
DeviationTypeCategoryName nvarchar(255)
I am currently making use of automapping with conventions.
When I create an instance of Deviation, I would like to be able to do something like the following:
var deviation = new Deviation{DeviationType=DeviationEnum.NoMatchMobileNumber};
Now as far as I know enums only support integral types, so this won't work without an alternative approach. I was thinking of maybe using a dictionary to this, like Dictionary<DeviationEnum,Guid>
, and I also suspect I might need to make use of UserTypeConvention<T>
to make this work somehow.
Anyone got experiences to share?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我传统上所做的是使用自定义 IUserType 类,该类将在相关枚举及其持久化方式之间进行转换。但是,这需要每个枚举类型有一个自定义 IUserType。
What I've traditionally done is use a custom IUserType class that would translate between the enum in question and how it would be persisted. However, this required a custom IUserType per enum type.