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修复,布布扣,bubuko.com