I am using NHibernate to pull some data out of a legacy db, and I have found several cases where there is a foreign key, but the referenced row has been removed.
When I make my NHibernate mapping (using Fluent NHibernate like so:
References(d => d.Group)
.WithColumns("groupId", "dataset")
.SetAttribute("lazy", "true");
I get an unitialized proxy for Group
when loading the root object, followed by an ObjectNotFoundException
when I attempt to use it.
If I disable lazy loading, I get an ObjectNotFoundException
immediately when loading the root.
Therefore: Is there a way to have NHibernate make the Group
null when loading the root? Or is it possible to check the unitialized proxy somehow, to see if it will succeed in loading the row?
I found the solution here - i needed to add
.SetAttribute("not-found", "ignore");
to the mapping.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With