使用 nHibernate Linq Provider 将查询枚举存储为字符串
我目前有一个枚举作为字符串保存在数据库中。我现在使用 nHibernate 的 Linq 提供程序对此枚举进行查询和过滤,但我不断收到异常。
我尝试将枚举与枚举列表进行比较,尝试过 .ToString() 我仍然无法让它工作。
自定义约定仅对分离标准有效吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我使用 GenericEnumMapper 并且链接查询从未遇到任何问题。
但不知道如何将其应用于自动映射,因为我很少使用它。也许是这样的
I use GenericEnumMapper and never had any problems with link queries.
Not sure how to apply this to AutoMapping though because I rarely use it. Maybe something like this
您使用 Fluent NHibernate 吗?如果是这样,您可以使用 Map()...
另外,请确保您的 Automapping 不与 Fluent NH 冲突,并且您正确注册了所有约定。
Are you using Fluent NHibernate? If so, you can user Map()...
Also, make sure your Automapping does not conflict with Fluent NH and that you correctly registered all your conventions.
您需要创建一个自定义 IUserType 将枚举与其字符串表示形式相互转换。 C# 有一个很好的例子 此处
还有一篇相同的帖子:http://softwareblog.morlok.net/ 2009/07/02/mapping-enums-to-custom-strings-in-nhibernate/
希望对您有帮助..
You need to create a custom IUserType to convert an enum to its string representation and back. There's a good example in C# here
There is one more post abt the same: http://softwareblog.morlok.net/2009/07/02/mapping-enums-to-custom-strings-in-nhibernate/
Hope that helps you..