Reputation: 6743
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 ?
Upvotes: 2
Views: 960
Reputation: 1493
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>>();
});
Upvotes: 2
Reputation: 15579
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..
Upvotes: 1
Reputation: 3572
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.
Upvotes: 1