开发者

Query Enums stored as string using nHibernate Linq Provider

开发者 https://www.devze.com 2023-03-29 06:21 出处:网络
I currently have an Enu开发者_如何学Gom 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 currently have an Enu开发者_如何学Gom 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 ?


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>>();
});


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.


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..

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号