Foreign Keys - HomeroThompson/firehawk GitHub Wiki

Foreign Keys

Foreign Key names can also be customized. The following list describes the set of naming conventions available for foreign key names:

Default

The default behavior. The database decides the foreign key name. This is the default convention so there is no need to set this value explicitly.

.ConfigureDatabaseConventions()
    .UseConventionForForeignKeyNames(ForeignKeyNamingConvention.Default)
.EndConfig()

Example Let's suppose that we've a {{Customer}} class with a list of {{Phones}}. In this case the foreign key will be created on the {{Phone}} table

public class Customer
{
    public virtual long ID { get; set; }
    public virtual string Name { get; set; }
    public virtual IReadOnlyCollection<Phone> { get; private set; }
}

public class Phone
{
    public virtual string Number { get; set; }
    public virtual PhoneType Type { get; set; }
}

On the Phone table, The database could generate a foreign key whose name is like:

FK65421548844
FK_FKTable_PKTable

The foreign key name consists on the FK prefix appended to the foreign key table name and the primary key table name.

.ConfigureDatabaseConventions()
    .UseConventionForForeignKeyNames(ForeignKeyNamingConvention.FK_FKTable_PKTable)
.EndConfig()

Example: On the Phone table, Firehawk will generate a foreign key whose name is like:

FK_PHONE_CUSTOMER
FK_FKTable_PKTable_PKColumn

The foreign key name consists on the FK prefix appended to the foreign key table name and the primary key table name plus the PK column name

.ConfigureDatabaseConventions()
    .UseConventionForForeignKeyNames(ForeignKeyNamingConvention.FK_FKTable_PKTable_PKColumn)
.EndConfig()

Example: On the Phone table, Firehawk will generate a foreign key whose name is like:

FK_PHONE_CUSTOMER_ID
FKTable_PKTable_PKColumn_FK

The foreign key name consists on the foreign key table name appended to the primary key table name, the primary key property name plus the FK suffix.

.ConfigureDatabaseConventions()
    .UseConventionForForeignKeyNames(ForeignKeyNamingConvention.FKTable_PKTable_PKColumn_FK)
.EndConfig()

Example On the {{Phone}} table, Firehawk will generate a foreign key whose name is like:

PHONE_CUSTOMER_ID_FK
FKTable_PKTable_FK

The foreign key name consists on the foreign key table name appended to the primary key table name plus the FK suffix.

.ConfigureDatabaseConventions()
    .UseConventionForForeignKeyNames(ForeignKeyNamingConvention.FKTable_PKTable_FK)
.EndConfig()

Example On the Phone table, Firehawk will generate a foreign key whose name is like:

PHONE_CUSTOMER_FK
Custom

The foreign key name is generated using a custom user defined function. The input parameters are the entity type, the foreign key property info and the primary key property info.

.ConfigureDatabaseConventions()
    .UseCustomConventionForForeignKeyNames((e, f, p) =>
    { 

    })
.EndConfig()
⚠️ **GitHub.com Fallback** ⚠️