0

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!

Community
  • 1
  • 1
Chris
  • 555
  • 2
  • 9
  • 28
  • I don't understand your question at all... – Phill Jul 20 '11 at 23:40
  • @Phill Maybe said a different way: I want to control nhibernate's not found behavior based on the Id I'm asking for. Imagine I have a table that has neither a row with Id 0 nor a row with Id 12. I want to control the NotFound behavior such that requesting Id 0 returns null but requesting Id 12 throws an exception. The simple solution would be to leave the default NotFound behavior (throwing exception) and add a dummy row with Id of 0, but unfortunately we're not confident what in the app relies on getting null back when Id 0 is requested. – Chris Jul 21 '11 at 15:44

1 Answers1

0

This isn't perfect, but anyone looking to do this kind of thing should take a gander here

Chris
  • 555
  • 2
  • 9
  • 28