NHibernate 的 SetResultTransformer 方法在Oracle下的Bug修复
NHibernate 的 SetResultTransformer 方法在Oracle下会出现“Could not find a setter for property”错误,这是Nhibernate在Oracle下使用的一个Bug。针对此Bug我可以自己进行修复。
下载NHibernate源码,将Property下的“ChainedPropertyAccessor.cs”稍作修改就会修复此Bug,代码如下:
using System; namespace NHibernate.Properties { using System.Text.RegularExpressions; [Serializable] public class ChainedPropertyAccessor : IPropertyAccessor { private readonly IPropertyAccessor[] chain; public ChainedPropertyAccessor(IPropertyAccessor[] chain) { this.chain = chain; } #region IPropertyAccessor Members public IGetter GetGetter(System.Type theClass, string propertyName) { for (int i = 0; i < chain.Length; i++) { IPropertyAccessor candidate = chain[i]; try { return candidate.GetGetter(theClass, propertyName); } catch (PropertyNotFoundException) { // ignore } } throw new PropertyNotFoundException(theClass, propertyName, "getter"); } public ISetter GetSetter(System.Type theClass, string propertyName) { for (int i = 0; i < chain.Length; i++) { IPropertyAccessor candidate = chain[i]; try { return candidate.GetSetter(theClass, ToModelName(propertyName)); } catch (PropertyNotFoundException) { // } } throw new PropertyNotFoundException(theClass, propertyName, "setter"); } public bool CanAccessThroughReflectionOptimizer { get { return false; } } #endregion private static string ToModelName(string str) { str = str.ToLower(); var temp = Regex.Replace(str, @"_[a-z]?",m=>m.ToString().Substring(1).ToUpper()); var result = Regex.Replace(temp, @"^[a-z]?", m => m.ToString().ToUpper()); return result; } } }
NHibernate 的 SetResultTransformer 方法在Oracle下的Bug修复,古老的榕树,5-wow.com
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。