1
我想使用Example.Create()來查詢一個實例的唯一值。要做到這一點,我需要找出已經設置映射文件中的唯一鍵屬性的值,就像這樣:如何使用NHibernate查詢唯一鍵值
<property name="MyColumn">
<column name="MyColumn" unique-key="MyUniqueKeyGroup"/>
</property>
爲了更好地理解 - 這裏是代碼的重要組成部分:
criteria.Add(Example.Create(myObject).SetPropertySelector(new MyPropertySelector()));
[...]
public class MyPropertySelector: NHibernate.Criterion.Example.IPropertySelector
{
#region IPropertySelector Member
public bool Include(object propertyValue, string propertyName, IType type)
{
/* here is where I want to check if the property belongs
* to the unique-key group 'MyUniqueKeyGroup' and return true if so
*/
}
#endregion
}
我需要做什麼,找出屬性是否屬於唯一鍵組「MyUniqueKeyGroup」?
謝謝!使用NHibernate.Cfg.Configuration是我需要的提示。我原本以爲我可以使用SessionFactory.GetClassMetadata()函數來解決這個問題。 – Martin 2009-09-15 09:43:09