我收到此错误:
无法转换类型的对象
'NHibernate.Collection.Generic.PersistentGenericSet1[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:
<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>
怎么了?
你的问题是你正在使用ISet http://msdn.microsoft.com/en-us/library/dd412081.aspx in System.Collections.Generic
名称空间,但 nHibernate 期望 ISet 是Iesi.Collections.Generic.ISet<>
。因此,将您的属性定义更改为
public virtual Iesi.Collections.Generic.ISet<People> People { get; set; }
如果你想使用.net 4ISet<>
界面,通过这个article http://nhibernate.info/blog/2011/03/15/using-lt-set-gt-in-mappings-without-iesi-collections-net-4.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)