佩德罗,
搜索 NHibernate 代码我可以找到以下关于 IPersistentCollection (@event.Collection) 的 GetValue 方法的文档:
/// <summary>
/// Return the user-visible collection (or array) instance
/// </summary>
/// <returns>
/// By default, the NHibernate wrapper is an acceptable collection for
/// the end user code to work with because it is interface compatible.
/// An NHibernate PersistentList is an IList, an NHibernate PersistentMap is an IDictionary
/// and those are the types user code is expecting.
/// </returns>
object GetValue();
有了这个,我们可以得出结论,您可以将您的集合转换为 IEnumerable 并且一切正常。
我已经建立了一个映射包的小样本,这里的事情就是这样:
public void OnPostUpdateCollection(PostCollectionUpdateEvent @event)
{
foreach (var item in (IEnumerable)@event.Collection.GetValue())
{
// DO WTVR U NEED
}
}
希望这可以帮助!
菲利普