Skip to content

Default library conventions

MoonStorm edited this page Jun 3, 2024 · 8 revisions

OrmConfiguration.Conventions contains the default convention rules used by the library. You can set this property with an instance of your own conventions. Your class must derive from OrmConventions, where you can override a set of default rules.

Table names

In the absence of a Table attribute, the library will use the plural name of your entity for the database table name. This is done through a small set of regular expressions for the English language. You can extend this set by calling AddEntityToTableNameConversionRule method. ClearEntityToTableNameConversionRules clears the set.

Alternatively you can override the GetTableName method and return the non-delimited table name.

You can also use a library such as Humanizer for providing the plural form of your entity names that would match your db tables.

Schema names

The schema name is extracted from the Schema property of the Table attribute. If you wish to change this behavior, override the GetSchemaName method and return the non-delimited schema for your table(s).

Property discovery

By default, the library will look for all the public read-write properties that are not decorated with the NotMappedAttribute and are either of a "simple" type or are decorated with the ColumnAttribute, DatabaseGeneratedAttribute or the DatabaseGeneratedDefaultValueAttribute attribute. You can extend the list of "simple" types by overriding IsSimpleSqlType. Another alternative would be to change the way db bound properties are being discovered by overriding GetEntityProperties.

Property mappings

The System.ComponentModelnamespace exposes a good set of attributes, which are being used by the library to set up the property mappings. If no ORM specific attributes were found on the entity or on any of the properties, a property named Id, if found, will be set as a database generated, primary key.

Change the way properties are being set up by overriding ConfigureEntityPropertyMapping. The method receives a property mapping as an argument, which exposes various methods for setting up the property (e.g. SetPrimaryKey, SetDatabaseGenerated, etc).

Entity collections for navigation properties

The library calls the conventions to have the collection of entities in a parent-children relationship created. You can provide your own collection, as long as it implements an IList<TChildEntity>, by overriding the method CreateEntityCollection.

SQL dialect settings

Override GetDatabaseOptions for tuning the way SQL statements are being generated by the library. This includes delimiter wrapping of SQL identifiers. Prepare an instance of a new class that derives from SqlDatabaseOptions and return it every time GetDatabaseOptions gets called.