Search code examples
nhibernatefluent-nhibernatefluent

How to set default-cascade in Fluent NHibernate


I find we can specify the "default-cascade" attribute of the element. But how can I do it in Fluent NHibernate? And I don't want to use AutoMapping.


Solution

  • The detailed description could be found here: https://github.com/jagregory/fluent-nhibernate/wiki/Conventions. An extract:

    There are some situations that are so obvious that they just cried out for a simple shortcut that can be applied globally to your project:

    Table.Is(x => x.EntityType.Name + "Table")
    ...
    DefaultCascade.All()
    ...
    

    And this way we can use it:

    Fluently.Configure()
      .Database(/* database config */)
      .Mappings(m =>
      {
        m.FluentMappings
          .AddFromAssemblyOf<Entity>()
          .Conventions.Add(DefaultCascade.All());
      })
    

    Also check this, to get some idea how to implement own Conventions Fluent NHibernate automapping and cascading