【发布时间】:2012-05-30 22:12:07
【问题描述】:
让我们假设以下集合:
<list name="Items" inverse="true" cascade="all-delete-orphan" lazy="extra">
<key column="ItemId"/>
<index column="Sortorder" />
<one-to-many class="MyProject.Model.Item, MyProject"/>
</list>
最初是lazy="true",但我想提高性能。只要有物品,它就可以很好地工作。如果没有,下面的语句会产生System.InvalidCastException: Object cannot be cast from DBNull to other types.:
if (items.Count > 0) { // Type of items: IList<item>
这确实适用于lazy="true"。我在这里错过了什么?
sl3dg3
编辑:整个堆栈跟踪:
[InvalidCastException: Object cannot be cast from DBNull to other types.]
System.DBNull.System.IConvertible.ToInt32(IFormatProvider provider) +56
System.Convert.ToInt32(Object value) +28
NHibernate.Persister.Collection.AbstractCollectionPersister.GetSize(Object key, ISessionImplementor session) +334
NHibernate.Collection.AbstractPersistentCollection.ReadSize() +132
NHibernate.Collection.PersistentList.get_Count() +12
MyProject.Provider.MyProvider.SomeMethod() in [...]
第二次编辑:
如果我使用调试器打开集合,则有一个来自源 mscorelib 的 HResult,听起来好像错误已经出现在 .com - 世界的深处......
【问题讨论】:
标签: c# nhibernate mapping