无法将类型为“NHibernate.Collection.Generic.PersistentGenericSet`1[VideoStorageManager.Dal.Model.Monitor]”的对象强制转换为类型“Iesi.Collections.Generic.ISet`1[VideoStorageManager.Dal.Model.Monitor]”。
报的以上错误,目前完全没有头绪,希望有懂的大大回复我。
/// <summary>
/// 相机信息
/// </summary>
private ISet<Monitor> _monitors = new HashedSet<Monitor>();
把这个换成IList
<one-to-many class="Monitor"/>应该对应的是IList
报类似错误……
@Dfly:
<!--The foreign keys--> <bag name="Aaa" cascade="none" lazy="true" table="Addr_BusinessArea"> <key column="CityID" /> <one-to-many class="Ets.CRM.Repository.Bbb, Ets.CRM.Repository" /> </bag> public virtual IList<Bbb> Aaa { get { return this.aaa; } set { this.aaa= value; } }
这是我们的例子,你可以参考一下
@ArnoldZhang: 好,我先试试
@ArnoldZhang:你的方式可以,但是我还是不太明白,因为我确实用过HashedSet可以的,只是因为同事把表结构改的有点多而且没有通知我才会出现这个问题的,不知道你可能给我更好的解答。
@Dfly: 用hashedset当然可以的。你得这么配置。
<set name="Users" table="TBLPURCHASEGROUPUSER" inverse="false" lazy="false">
<key column="PURCHASE_GROUP_ID"/>
<many-to-many class="User" column="USER_ID"/>
</set>
这样用private ISet<User> _users;
或者new HashedSet<User>();
这两种方式都可以的。
Model中集合类型与配置文件不一致
配置文件写的
<set name="Monitors" table="ebs_monitor`" generic="true" inverse="true">
<key column="EQUIPMENTID" foreign-key="Fk_NvrMonitor"/>
<one-to-many class="Monitor"/>
Model中写的这样
/// <summary>
/// 相机信息
/// </summary>
private ISet<Monitor> _monitors = new HashedSet<Monitor>();
应该没问题吧?