Relationships - HomeroThompson/firehawk GitHub Wiki

Relationships

One-to-one, many-to-one and one-to-many relationships are mapped automatically by Mapping by Code Conventions, but there is a relationship that needs to be mapped by hand: many-to-many. This relationship is also special because it gets mapped to a separate table containing the foreign-key values that relates both sides of the relationship.

Firehawk provides a set of naming conventions used to generate the name of this intermediate table.

Default

The table name is generated by appending the name of the first table and the name of the second one.

.ConfigureDomainModelConventions()
  .UseConventionForManyToManyTableNames(ManyToManyTableNamingConvention.Default)
.EndConfig()

Example Lets suppose that we have two entities, {{Product}} and {{Category}}. A Product can belong to multiple Categories and of course a Category has multiple products.

public class Product
{
  public virtual long ID { get; set; }
  public virtual string Name { get; set; }
  public virtual string Description { get; set; }
  public virtual ICollection<Category> Categories { get; set; }
}

public class Category
{
  public virtual long ID { get; set; }
  public virtual string Name { get; set; }
  public virtual ICollection<Product> Products { get; set; }
}

Firehawk will generate a many to many table whose name is like this:

ProductCategory
FirstTableNameToSecondTableName

The table name is generated by appending the name of the first table and the name of the second table using the To preposition to separate them.

.ConfigureDomainModelConventions()
  .UseConventionForManyToManyTableNames(ManyToManyTableNamingConvention.FirstTableNameToSecondTableName)
.EndConfig()

Example Firehawk will generate a many to many table whose name is like this:

ProductToCategory
FirstTableName_SecondTableName

The table name is generated by appending the name of the first table and the name of the second table using the underscore character as word separator.

.ConfigureDomainModelConventions()
 .UseConventionForManyToManyTableNames(ManyToManyTableNamingConvention.FirstTableName_SecondTableName)
.EndConfig()

Example Firehawk will generate a many to many table whose name is like this:

Product_Category
Custom

The table name is generated by an user defined function. This function accepts as input parameters the entity types of the relationship.

.ConfigureDomainModelConventions()
  .UseCustomConventionForManyToManyTableNames((s,t) => 
  {
  })
.EndConfig()
⚠️ **GitHub.com Fallback** ⚠️