佩德罗,
搜索NHibernate的代码,我可以找到关于IPersistentCollection的GetValue方法(@ event.Collection)以下文档:
/// <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
}
}
希望这有助于!
菲利佩
伟大的作品!唯一要注意的是投给IList。使用映射为Set而不是Bag的集合,接口是ICollection,所以我们应该使用IEnumerable。谢谢! – Pedro 2010-08-12 14:22:31
好点。将我的答案更改为IEnumerable。 – jfneis 2010-08-12 15:17:46