得到“无法将PersistentGenericSet转换为ISet"的信息.错误 [英] Getting "unable to cast PersistentGenericSet to ISet" error
问题描述
我收到此错误:
无法转换类型的对象 'NHibernate.Collection.Generic.PersistentGenericSet
1[IocWinFormTestEntities.People]' to type 'System.Collections.Generic.ISet
1 [IocWinFormTestEntities.People]'.
Unable to cast object of type 'NHibernate.Collection.Generic.PersistentGenericSet
1[IocWinFormTestEntities.People]' to type 'System.Collections.Generic.ISet
1[IocWinFormTestEntities.People]'.
实体:
public class Event
{
public Event()
{
this.People = new HashSet<People>();
}
public virtual Guid Id { get; private set; }
public virtual ISet<People> People { get; set; }
}
地图覆盖类:
public class EventMapOverride : IAutoMappingOverride<Event>
{
public void Override(AutoMapping<Event> mapping)
{
mapping.HasMany(c => c.People)
.AsSet()
.Cascade.AllDeleteOrphan();
}
}
从流利的自动映射器生成的hbm:
Generated hbm from fluent automapper:
<set cascade="all-delete-orphan" name="People">
<key>
<column name="Event_id" />
</key>
<one-to-many class="IocWinFormTestEntities.People, IocWinFormTestEntities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</set>
怎么了?
推荐答案
您的问题是您使用的是System.Collections.Generic名称空间中的"nofollow noreferrer> ISet ,但nHibernate期望ISet为Iesi.Collections.Generic.ISet<>
.因此,将属性定义更改为
Your problem is you are using ISet in System.Collections.Generic
namespace but nHibernate expects ISet to be Iesi.Collections.Generic.ISet<>
. So change your property definition to
public virtual Iesi.Collections.Generic.ISet<People> People { get; set; }
If you want to use .net 4 ISet<>
interface, go through this article
这篇关于得到“无法将PersistentGenericSet转换为ISet"的信息.错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!