Let's imagine a situation.
I want to get an object with some ID.
If this ID is Category's ID, I get an exception instead of returning NULL. I think it is not a right behavior. Updated at 28.10.2009 14:58:16[InvalidCastException: Unable to cast object of type 'W3P.Model.BlogCategory' to type 'W3P.Model.BlogPost'.] Xtensive.Storage.Query`1.SingleOrDefault(Object[] keyValues) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage\Query{T}.cs:87 ... Updated at 28.10.2009 15:09:12Yes. I suppose a category object was fetched earlier and stored in cache. This thread was imported from our support forum. The original discussion may contain more detailed answer. Original topic by buck. |
Thanks!
It seems that we successfully fetched the instance of BlogCategory type by given ID and tried to cast it to the required type (BlogPost). At least, there could be thrown more adequate exception, but NULL as a result is preferable.
To be fixed.
Yep, you were definitely right. Entity of wrong type (but from the same hierarchy) was taken from Session cache and Key.Type check was omitted.
Fixed. See nightly build.
Could you provide us with the stack trace? This will be quite useful.