I am building an application on top of a legacy database. Unfortunately, I've come across a foreign key which is set to zero (0) instead of null to indicate the primary key entity is missing.
As there are many other applications running on top of this database, there is not chance I can fix the data. So I have to create my mappings to cope with this situation. Making NHibernate deal with this situation is challenging.
So on my foreign key property I've specified not-found="ignore" so the property becomes null when the foreign key property is dereferenced. However, when I join fetch from the foreign key's entity to the primary key's entity, I get a new Select query issued whenever I use the foreign key property. I believe this is a bug - fetch join should have no need to issue new selects to determine if the fetched entity is null (when not-found="ignore") when the purpose of the join fetch was to obtain the data upfront.
Are there any workarounds for this situation? I've had the idea of using a Formula Property, say, called DoesReallyExist. Are there any other nicer workarounds?
|