使用 nHibernate Linq Provider 将查询枚举存储为字符串

发布于 2024-11-29 23:27:22 字数 152 浏览 5 评论 0 原文

我目前有一个枚举作为字符串保存在数据库中。我现在使用 nHibernate 的 Linq 提供程序对此枚举进行查询和过滤,但我不断收到异常。

我尝试将枚举与枚举列表进行比较,尝试过 .ToString() 我仍然无法让它工作。

自定义约定仅对分离标准有效吗?

I currently have an Enum being staved as a string in the database. I now what to wuery and filter on this Enum using the Linq Provider for nHibernate but I keep getting exceptions.

I have tried comparing the Enum to a list of Enums, tried .ToString()
and I am still unable to get it to work.

are the custom conventions only active to the Detached Criteria ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

倦话 2024-12-06 23:27:22

我使用 GenericEnumMapper 并且链接查询从未遇到任何问题。

Map(x => x.Status).CustomType<GenericEnumMapper<MerchantStatus>>();

但不知道如何将其应用于自动映射,因为我很少使用它。也许是这样的

.Override<MerchantStatus>(map =>
{
  map.Map(x => x.Status)
    .CustomType<GenericEnumMapper<MerchantStatus>>();
});

I use GenericEnumMapper and never had any problems with link queries.

Map(x => x.Status).CustomType<GenericEnumMapper<MerchantStatus>>();

Not sure how to apply this to AutoMapping though because I rarely use it. Maybe something like this

.Override<MerchantStatus>(map =>
{
  map.Map(x => x.Status)
    .CustomType<GenericEnumMapper<MerchantStatus>>();
});
2024-12-06 23:27:22

您使用 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.

姜生凉生 2024-12-06 23:27:22

您需要创建一个自定义 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..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文