Primary Key Columns - HomeroThompson/firehawk GitHub Wiki

Primary Key Columns

While the column naming conventions let you choose the casing rule for the column names, primary key column conventions let you decide how the name of the primary key columns are composed. Generally, primary column names receive a special treatment (like appending the table name to the identifier property name) in order to distinguish them from the other columns.

These are the availabe conventions:

Default

The primary key column name is the same as the property name. This is the default convention so there is no need to set this value explicitly.

.ConfigureNamingConventions()
    .UseConventionForPrimaryKeyColumnNames(PrimaryKeyColumnNamingConvention.Default)
.EndConfig()

Example: Let's suppose that the Customer entity has an ID property called ID. In this case the primary key column name would be just ID

public class Customer
{
    public virtual long ID { get; set; }
    public virtual string Name { get; set; }
}

Result: (Customer table)

ID Name
... ...
EntityNameIDPropertyName

The primary key column name is generated by appending the entity name and the primary key property name.

.ConfigureNamingConventions()
    .UseConventionForPrimaryKeyColumnNames(
        PrimaryKeyColumnNamingConvention.EntityNameIdPropertyName)
.EndConfig()

Example: In this case the primary key column name would be CustomerId

Result: (Customer table)

CustomerID Name
... ...
EntityName_IDPropertyName

The primary key column name is generated by appending the entity name and the primary key property name using the underscore character as a word separator.

.ConfigureNamingConventions()
    .UseConventionForPrimaryKeyColumnNames(
        PrimaryKeyColumnNamingConvention.EntityName_IdPropertyName)
.EndConfig()

Example: In this case the primary key column name would be Customer{"_"}Id

Result: (Customer table)

Customer_ID Name
... ...
Custom

The primary key column name is generated by an user defined function. This function receives as input parameters the entity type and the primary key property memeber info.

.ConfigureNamingConventions()
    .UseCustomConventionForPrimaryKeyColumnNames((e, m) => 
    {

    })
.EndConfig()