2011-08-18 21 views
1

我得到这个异常:无法投PersistentGenericBag到ISet的例外

无法转换'NHibernate.Collection.Generic.PersistentGenericBag`1[System.Int64]'类型的对象类型'System.Collections.Generic.ISet`1[System.Int64]'

我用:

public virtual ISet<long> Ids { get; set; } 

我不使用FNH进行任何明确的映射。

+0

使用Iesi.Collections.Generic.ISet explictely似乎这样的伎俩ICollection<T>接口,但我读的地方,NHibernate的应该是能够应付.net 4的iset以及...? – cs0815

回答

1

如果将您的藏品映射为Bag,则应在实体中使用IList<T>进行收藏。

如果映射为Set,那么你要么可以使用来自Iesi.Collections ISet<T>或.NET

+0

这就是我所做的,它仍然不起作用(它不会持续)。请参阅:http://stackoverflow.com/questions/7109438/fluent-nhibernate-problem – cs0815

1

NHibernate不支持NET4 ISet开箱即用。您需要添加this package

+0

谢谢。我能不能只使用Iesi.Collections.Generic.ISet?另请参阅相关问题:http://stackoverflow.com/questions/7109438/fluent-nhibernate-problem – cs0815

+0

是的,你可以。这就是它的目的。您也可以使用'ICollection '。 –