標籤:使用 os io for ar cti 代碼 new
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; } }}