Foreign Key Columns - HomeroThompson/firehawk GitHub Wiki
Similar to Primary Key columns, you can customize the way foreign key columns names are generated. This allows you to distinguish the foreign key columns from the other columns. Next is the available set of conventions that apply to foreign key columns:
The foreign key column names are the same as property names. This is the default behavior and you don’t need to set it explicitly.
.ConfigureNamingConventions()
.UseConventionForForeignKeyColumnNames(ForeignKeyColumnNamingConvention.Default)
.EndConfig()
The foreign key column names are generated based on the relationship target entity name.
.ConfigureNamingConventions()
.UseConventionForForeignKeyColumnNames(
ForeignKeyColumnNamingConvention.TargetEntityName)
.EndConfig()
Example: As an example, let’s suppose that our Customer entity has a list of phones. In this case, the Phone table would have a foreign key column making reference to the Customer table.
public class Customer
{
public virtual long ID { get; set; }
public virtual string Name { get; set; }
public virtual IReadOnlyCollection<Phone> Phones {get; private set;}
}
public class Phone
{
public virtual string Number { get; set; }
public virtual PhoneType Type { get; set; }
}
Result: (Phone table)
Customer | Number | Type |
---|---|---|
... | ... | ... |
The foreign key column names are generated based on the relationship’s target entity name and its ID property name.
.ConfigureNamingConventions()
.UseConventionForForeignKeyColumnNames(
ForeignKeyColumnNamingConvention.TargetEntityNameIdPropertyName)
.EndConfig()
Example: Customer entity with a list of phones.
Result: (Phone table)
CustomerID | Number | Type |
---|---|---|
... | ... | ... |
The foreign key column names are generated based on the relationship’s target entity name and its ID property name. In this case the entity name and the ID property name are separated by the underscore character.
.ConfigureNamingConventions()
.UseConventionForForeignKeyColumnNames(
ForeignKeyColumnNamingConvention.TargetEntityName_IdPropertyName)
.EndConfig()
Example Customer entity with a list of phones.
Result: (Phone table)
Customer_ID | Number | Type |
---|---|---|
... | ... | ... |