views:

19

answers:

1

I'm using fluent-nhibernate conventions to map my entityies:

 public class HasManyConvention : IHasManyConvention
    {
        public void Apply(FluentNHibernate.Conventions.Instances.IOneToManyCollectionInstance instance)
        {
            instance.Key.Column(instance.EntityType.Name + "ID");
            instance.Cascade.AllDeleteOrphan();
        }
    }

so this convention generate the following hibernate mapping :

<class xmlns="urn:nhibernate-mapping-2.2" mutable="true" name="ParentType, ParentTypeAssembly" table="ParentTable">
   <id name="ParentIDID" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" unsaved-value="0">
     <column name="ParentID" />
     <generator class="identity" />
   </id>

    <bag cascade="all-delete-orphan" name="Childs" mutable="true">
      <key>
        <column name="ParentID" />
      </key>
      <one-to-many class="ChildType, ChildTypeAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    </bag>
  </class>
</hibernate-mapping>

how can i modify the convention to make the ParentID in the child table not null?

so it will look like this :

  <key>
    <column name="ParentID" not-null="true" />
  </key>
A: 

There does not appear to be any way to do this in the convention. Looking at the tests for implementing the HasManyConvention and the methods on the IOneToManyCollectionInstance interface I don't see any way to set not-null.

You might want to take a look at this question though.

CuriousCurmudgeon

related questions