1
votes

Components which have no value assigned to any child property will also be set to null when being retrieved from the database.

I don't mind this, it's simply an additional check to see if the component is null or not. However when I try to then update or insert that object into the database with the null component I get the error:

"not-null property references a null or transient [full property name]" which seems rediculous, how come NHibernate will pass me a NULL however it won't accept it itself.

Is there some mapping option I am missing to override this or do i really have to set the component to a value before updating or inserting into the database?

Thanks

1

1 Answers

3
votes

If all properties are null the component is null itself when you write, it's a normal behaviour.

When you get from the database if you use an auto-property with a public setter you can have this kind of problem.

if you have this :

public virtual MyComponent MyComponentObject { get; set; }  

you have to do this instead :

    private MyComponent _myComponent;
    public virtual MyComponent MyComponentObject 
    {
        get
        {
            if (ReferenceEquals(null, _myComponent))
            {
                _myComponent= new MyComponent();
            }
            return _myComponent;
        }
        set
        {
            _myComponent = value;
        }
    }

HTH,

Kris-I,