1
我試圖讓fNH映射到自定義類型,但我遇到了困難。自定義類型的流暢的nHibernate配置
我希望fNH通過接口將其值分配給自定義類型。我還需要nHibernate來保留實體上自定義類型的實例。當訪問屬性時,它將始終被實例化,不會覆蓋實例,只需設置包裝的值。
當我嘗試下面的映射,它拋出一個異常「找不到類「Entities.User屬性‘值’吸氣」
想法?
FNH映射:
Map(x =>((IBypassSecurity<string>)x.SecuredPinNumber).Value,"[PinNumber]");
域例如:
public class User
{
public SecureField<string> SecuredPinNumber {get;private set;}
}
public class SecureField<T> : IBypassSecurity<T>
{
public T Value { get; set; } // would apply security rules, for 'normal' use
T IBypassSecurity<T>.Value {get;set;} // gets/sets the value directy, no security.
}
// allows nHibernate to assign the value without any security checks
public interface IBypassSecurity<T>
{
T Value {get;set;}
}
感謝您的帖子鏈接。關於使用CustomType,我已經看了一個例子,從例子的外觀來看,它創建了一個SecureField類型的新實例,並返回它,我不想要。有什麼辦法可以避免這種情況? – jasper