tag:blogger.com,1999:blog-18388564.post116658401877033860..comments2024-01-25T16:16:23.048-09:00Comments on Oran Dennison: Generic NHibernate Enum String MappingOran Dennisonhttp://www.blogger.com/profile/18170789721507988932noreply@blogger.comBlogger17125tag:blogger.com,1999:blog-18388564.post-72650281709855921732014-03-24T01:37:56.063-08:002014-03-24T01:37:56.063-08:00some mor information would be greatsome mor information would be greatAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-18388564.post-70414635940490813142010-04-26T16:18:14.394-08:002010-04-26T16:18:14.394-08:00In my previous comment it should be MyAssembly.MyE...In my previous comment it should be MyAssembly.MyEnum (not MyClass).ncloudhttp://www.nicholascloud.comnoreply@blogger.comtag:blogger.com,1999:blog-18388564.post-50628613312750760352010-04-26T16:09:00.140-08:002010-04-26T16:09:00.140-08:00In the latest version of NHibernate (2.1.2) you ca...In the latest version of NHibernate (2.1.2) you can actually do this:<br /><br /><strong><br />type="NHibernate.Type.EnumStringType`1[[MyAssembly.MyClass, MyAssembly]], NHibernate"<br /></strong><br /><br />Thanks for the helpful post.ncloudhttp://www.nicholascloud.comnoreply@blogger.comtag:blogger.com,1999:blog-18388564.post-64223326398360675322010-04-08T06:37:16.148-08:002010-04-08T06:37:16.148-08:00golden .......golden .......PaRahttps://www.blogger.com/profile/05986987015497610565noreply@blogger.comtag:blogger.com,1999:blog-18388564.post-39654216073263022582010-02-15T07:00:42.749-09:002010-02-15T07:00:42.749-09:00Thanks for contributing this. I couldn't have ...Thanks for contributing this. I couldn't have found this without your blog-entry!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-18388564.post-4891401887894040562009-10-29T08:38:32.313-08:002009-10-29T08:38:32.313-08:00It helped me today.. Thank you for the good work.
...It helped me today.. Thank you for the good work.<br /><br />Reddy.Reddynoreply@blogger.comtag:blogger.com,1999:blog-18388564.post-23416074829147708502009-07-09T06:50:43.780-08:002009-07-09T06:50:43.780-08:00I would avoid changing the enum. But feel free to ...I would avoid changing the enum. But feel free to try it and find out... :-) Remember, there's no such thing as magic.Oran Dennisonhttps://www.blogger.com/profile/18170789721507988932noreply@blogger.comtag:blogger.com,1999:blog-18388564.post-55784550952778034872009-07-07T11:30:45.463-08:002009-07-07T11:30:45.463-08:00Forgive what may be a silly question, but at what ...Forgive what may be a silly question, but at what point do changes made tot he enum in code get persisted to the database?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-18388564.post-85568879750735730762009-06-03T18:01:33.189-08:002009-06-03T18:01:33.189-08:00If you're using NHibernate.Mapping.Attributes ...If you're using NHibernate.Mapping.Attributes this becomes even easier because you don't have to much with the .NET funky generics representation syntax, the reflection takes care of it:<br /><br /> [Property(TypeType=typeof(GenericEnumMapper&;t;ResponseType>))]<br />public virtual ResponseType Response { get; set; }<br /><br />Which generates the following mapping:<br /><br /><property name="Response" type="Namespace.GenericEnumMapper`1[[Namespace.ResponseType, Namespace.Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], Assembly" />jasonsirotahttps://www.blogger.com/profile/15891477995845832380noreply@blogger.comtag:blogger.com,1999:blog-18388564.post-87056519825860046872009-05-28T22:27:39.581-08:002009-05-28T22:27:39.581-08:00GenericEnumMapper may be defined in a different as...GenericEnumMapper may be defined in a different assembly than MyEnum. So in the example given, MyEnum lives in AssemblyA while GenericEnumMapper lives in AssemblyB.Oran Dennisonhttps://www.blogger.com/profile/18170789721507988932noreply@blogger.comtag:blogger.com,1999:blog-18388564.post-67716923824720647022009-05-28T00:00:47.799-08:002009-05-28T00:00:47.799-08:00Why are there references to AssemblyA and Assembly...Why are there references to AssemblyA and AssemblyB?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-18388564.post-33962657318701799782009-03-30T10:02:00.000-08:002009-03-30T10:02:00.000-08:00First, nice post! There are many reason to include...First, nice post! There are many reason to include the text of enums. It is amazing how performance is always emphasized when many, many scenarios would have virtually no performance impact for string versus int storage. How about reports or other contexts where the values are read-back? With string values, reports or exports are complete as-is. With enums, some form of lookup and conversion must be completed.<BR/><BR/>BTW: Have you noticed that your "What I read" links are in a box placed directly in the middle of your post and it covers the most important line of code? That is not good... it is like a very seriously annoying advertisement that won't go away.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-18388564.post-49163046201574442872008-09-11T11:04:00.000-08:002008-09-11T11:04:00.000-08:00Oran, thanks for the insight. I have taken what y...Oran, thanks for the insight. I have taken what you have done here along with additional information to create a transparent NHibernate enum mapper. It will allow you to map complex (special characters, puctuation, etc...) from your enum into a database. You can find it here.<BR/><BR/>http://geekswithblogs.net/ResultantCode/archive/2008/09/11/enums-and-nhibernate--taking-the-logic-out-of-the.aspxAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-18388564.post-66243984888445181522008-01-15T23:27:00.000-09:002008-01-15T23:27:00.000-09:00Thank you for the solution!It's ugly but it shows ...Thank you for the solution!<BR/>It's ugly but it shows the right direction.MatFizhttps://www.blogger.com/profile/08082787785063482610noreply@blogger.comtag:blogger.com,1999:blog-18388564.post-12402817469021921942007-12-03T08:32:00.000-09:002007-12-03T08:32:00.000-09:00Great post. Worked like a charm.Great post. Worked like a charm.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-18388564.post-65834156721311944392007-09-19T16:41:00.000-08:002007-09-19T16:41:00.000-08:00Works on my box! ;) Does the non-generic techniqu...Works on my box! ;) Does the non-generic technique described <A HREF="http://codebetter.com/blogs/jeffrey.palermo/archive/2006/03/14/140949.aspx" REL="nofollow">here</A> work? If not, the problem is somewhere in your project and it would be simplest to debug your problem using the non-generic solution first and then switch to the generic version once you figure it out. If the non-generic solution works, there may be something wrong with your generic syntax. You're using a backtick ` not a ' apostrophe right? And you're double-nesting your brackets like this, [[]]? Try doing a copy-paste-modify to make extra sure.Oran Dennisonhttps://www.blogger.com/profile/18170789721507988932noreply@blogger.comtag:blogger.com,1999:blog-18388564.post-29042049246523138672007-09-19T13:12:00.000-08:002007-09-19T13:12:00.000-08:00Avast! I tried your example and even checked it tw...Avast! I tried your example and even checked it twice. Keeps giving me an NHibernate.MappingException "could not interpret type..." Any ideas?Anonymousnoreply@blogger.com