Search code examples
nhibernatenhibernate-mappingnhibernate-mapping-by-code

Nhibernate Loquacious Mapping By Code (Not-Found=Ignore)


I am trying to create a ManyToOne map over a legacy database, as such need it to ignore any orphaned records.

The original xml way of describing it was:

<many-to-one not-found="ignore" />

But I am unable to describe it using NHibernate 3.2 Mapping by Code.

The code I am using to describe the map is below:

ManyToOne(x => x.Gang, manyToOne =>
        {
            manyToOne.Column("gang_code");
            manyToOne.Cascade(Cascade.None);
            manyToOne.NotNullable(true);
        });

The NotNullable(true) is there since there should always be a gang for a new or updated record, but need the record to be read/selected to allow users to change it.

Thanks in advance for any help you can provide, it's driving me nuts.


Solution

  • It's not yet supported. You can enter an issue at https://nhibernate.jira.com.

    In the meantime, keep using XML to map that class.

    You can also clone https://github.com/nhibernate/nhibernate-core and patch (I)ManyToOneMapper


    Edit: I implemented it in my fork. I'm too lazy to create the test, Jira and pull request now, but you can use it as-is.

    Edit: this is now implemented in the trunk; it will be available in the next release.