We're updating the issue view to help you get more done. 

InvalidCastException when deleting entities containing uninitialized lazy components


When trying to delete an entity having an uninitialized lazy component, InvalidCastException is thrown: Unable to cast object of type 'NHibernate.Intercept.UnfetchedLazyProperty' to type xxx.

I believe the problem lies at NHibernate.Engine.ForeignKeys.Nullifier, at NullifyTransientReferences. This method will try to walk through the component's property values regardless they have been initialized or not, and does not initialize the properties itself, nor does it throw any meaningful exception.
It would be nice if the uninitialized properties were initialized, or better the lazy properties were initialized only when there are any properties under the component's hierarchy which need to be nullified.
As we don't use associations and collections in out components, our workaround was to skip "nullification" of uninitialized components at all.

I have tested this using the following setups, and behavior was all the same: .NET 4.0 + Oracle.DataAccess, .NET 4.0 + System.Data.SQLite, .NET 2.0 + System.Data.SQLite

The attached test cases are to be imported into the standard NHibernate.Test project.





Alexander Zaytsev


Gabor Szecsi