From: Igor K. (JIRA) <nh...@gm...> - 2011-04-08 18:57:03
|
[ http://216.121.112.228/browse/NH-2637?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=20867#action_20867 ] Igor Krupin commented on NH-2637: --------------------------------- Oh, sorry. The bug is this. I have a database table called STUDENT. So we have something like STUDENT.FIRSTNAME STUDENT.LASTNAME In Oracle we uppercase everything (I hate Oracle, but whatever). Then, we have a class called Student, with properties FirstName and LastName (mixed case). The we do something like: ISQLQuery query = session.CreateSQLQuery("SELECT FIRSTNAME, LASTNAME FROM STUDENT"); query.SetResultTransformer(Transformers.AliasToBean(typeof(Student))); PROBLEM: AiasToBean will complain that it can't find setter property "FIRSTNAME". I traced the code to NHibernate.Properties.BasicPropertyAccessor.GetSetterOrNull method. It's looking for FIRSTNAME property, case sensitive, and can't find it. Igor > NHibernate.Properties.BasicPropertyAccessor.GetSetterOrNull is case sensitive > ----------------------------------------------------------------------------- > > Key: NH-2637 > URL: http://216.121.112.228/browse/NH-2637 > Project: NHibernate > Issue Type: Bug > Components: Core > Affects Versions: 3.1.0 > Reporter: Igor Krupin > Priority: Major > Attachments: Capture.PNG > > > We are running NH 2.1 and discovered this bug trying to upgrade to NH 3.1. We do a lot of AliasToBean stuff, mapping tables to DTOs, and AliasToBean will call this method to get the properties. Problem is, it's case sensitive now! Reading code comments i see this: > ============ <CODE SNIPPET> ================ > BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly; > if (type.IsValueType) > { > // the BindingFlags.IgnoreCase is important here because if type is a struct, the GetProperty method does > // not ignore case by default. If type is a class, it _does_ ignore case... we're better off explicitly > // stating that casing should be ignored so we get the same behavior for both structs and classes > bindingFlags = bindingFlags | BindingFlags.IgnoreCase; > } > ============ </CODE SNIPPET> ================ > "If type is a class, it _does_ ignore case..." -- incorrect. By default in classes case will _not_ be ignored, you explicitly have to specify it using a flag, same as you do for value type. > The fix for this is rather simple, just add the BindingFlags.IgnoreCase flag and all's good. No need for the "if (type.IsValueType)" anymore either. GetGetterOrNull suffers from the same. > Thank You!!! > Igor -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://216.121.112.228/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |