There are some shortcuts available for conventions that can be used inline (much like the old convention style); they're to be used for very simple situations where some people might think defining new types is overkill.

Creating implementations of the interface convention types is always the recommended approach, but if you think otherwise these are available.

Builders Edit

There is a ConventionBuilder class that you can use to define simple conventions. The general rule-of-thumb is if your convention has any logic, or spans multiple lines, then don't use the builders. That being said, they can be useful for simple scenarios.

The ConventionBuilder defines several static properties, one for just about all the available conventions. Through each property you can access two methods, Always and When. These can be used to create simple conventions that are either always applied, or only applied in particular circumstances.

Always Edit

These inline conventions are applied to every mapping instance of their type, they're handy for catch-all situations.

ConventionBuilder.Class.Always(x => x.Table(x.EntityType.Name.ToLower()))
ConventionBuilder.Id.Always(x => x.Column("ID"))

When Edit

These conventions are only applied when the first parameter evaluates to true.

  c => c.Expect(x.TableName, Is.Not.Set), // when this is true
  x => x.Table(x.EntityType.Name + "Table") // do this

Even shorter shortcuts Edit

There are some situations that are so obvious that they just cried out for an even simpler shortcut.

Table.Is(x => x.EntityType.Name + "Table")
PrimaryKey.Name.Is(x => "ID")
OptimisticLock.Is(x => x.Dirty())
Cache.Is(x => x.AsReadOnly())

Usage Edit

To use these conventions you just need to call Add on the fluent configuration Conventions property. This method accepts a generics parameter of T, where T is constrained to IConvention interfaces.

  .Database(/* database config */)
  .Mappings(m =>
      .Conventions.Add(PrimaryKey.Name.Is(x => "ID"));

The Add method accepts a params array, so you can specify multiple conventions together.

  PrimaryKey.Name.Is(x => "ID"),

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.