We're working in a legacy code base that's got a pretty rough data model. Right now, we have a Object Mapping that looks like this:
using FluentNHibernate.Mapping;
using Validation.Domain;
namespace Validation.DomainMaps
{
public sealed class BookMap : SubclassMap<Book>
{
public BookMap()
{
Map(x => x.Genre);
References(x => x.Shelf, "ShelfId")
.Nullable()
.Not.LazyLoad()
.NotFound.Ignore()
.Cascade.All()
.Fetch.Join();
}
}
}
In the application, a book without a shelf will have a ShelfId of 0. There is no row in the Shelf table with an Id of 0 and we are depending on nhibernate's .NotFound.Ignore()
to return null which we'll check for and handle later on.
This has gotten us this far but, now we're trying to throw an exception when we try and access non-0 ShelfId's that don't have entries in the Shelf table.
Ideally, nhibernate would throw an exception only in the case that it could not find a Shelf with a non-0 Id and return null when asked for a Shelf with an Id of 0.
Any help would be exceptional!