Component.NotFound

Maarten's Avatar

Maarten

30 Jul, 2010 12:15 PM via web

Hi,

I've added a component to the mapping of my Road object

            Component(x => x.Tm, m =>
            {
                m.Map(x => x.AxisFilename).Default("empty"); //  AxisFilename is a string
            });

When I set a break point in the setter of the Tm property, I see that FNH may call road.Tm = null.
This surprised me, because I would expect that a Tm is always constructed (using "empty" as a default value if the AxisFilename field is not filled in).
I've tried to solve this by initializing Tm to a valid object instance in the constructor of my Road class, and adding a NotFound.Ignore to the Component call, but found that NotFound is not supported for Component.

Is there an alternative way in FNH to achieve the desired behaviour?
Thanks, and keep up the good work!

Maarten

  1. Support Staff 2 Posted by James Gregory on 31 Jul, 2010 06:48 AM

    James Gregory's Avatar

    This is a design decision in NHibernate itself, not Fluent NHibernate.

    The null value semantics of a component are ad hoc. When reloading the
    > containing object, NHibernate will assume that if all component columns are
    > null, then the entire component is null. This should be okay for most
    > purposes.

    I'd recommend you familiarise yourself with how NHibernate works, rather
    than trying to work around it; however, I think I've heard of people doing
    this before:

    public Tm Tm
    {
      get
      {
        if (_tm == null)
          _tm = new Tm();

        return _tm;
      }
      set { _tm = value; }
    }

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    What comes next? 'Monday Tuesday Wednesday ?????'