Association Configuration Classes
In This Topic
Associations are created with the Association method of the EntityConfiguration class.
The example of defining an association mapping configuration:
builder.Entity<Order>()
.Association()
.Name(@"Company_Order")
.ToOne(order => order.Company).ThisKey(order => order.ShipCompanyID)
.FromMany(company => company.Orders).OtherKey(company => company.CompanyID);
The following classes are used to help defining association mapping configuration. Reflection-based classes:
Generic classes:
Each of these classes performs its own part of configuring the association mapping. All of them are descendants of the AssociationBaseConfiguration class, which implements the IAssociationConfiguration interface.
AssociationStartConfiguration and AssociationStartConfiguration<TThisEntity>
The AssociationStartConfiguration class has the following public methods:
- Name - specifies the association name.
- ToOne and ToMany - configure navigation properties.
AssociationOneEndConfiguration, AssociationOneEndConfiguration<TThisEntity, TOtherEntity>, AssociationManyEndConfiguration, and AssociationManyEndConfiguration<TThisEntity, TOtherEntity>
The AssociationOneEndConfiguration and AssociationManyEndConfiguration classes have the following public methods:
- ThisKey - specifies the foreign key properties.
- ThisStorage - specifies non-public property or field for LinqConnect to work with instead of the navigation property. Usually it is used when the navigation property setter should perform some additional logics.
- FromParentOne, FromChildOne, and FromMany - specify the navigation property from the other end of the relationship. If you want to define a unidirectional association with no navigation property on the other side of the association, use the overloads of these methods with no parameters.
AssociationConfiguration and AssociationConfiguration<TOtherEntity>
The AssociationConfiguration class has the following public methods:
- Name - specifies the association name.
- OtherKey - specifies the association properties on the other end of the association.
- OtherStorage - specifies non-public property or field for LinqConnect to work with instead of the navigation property on the other end of the association.
- DeleteOnNull - specifies that if the navigation property of a dependent entityis set to NULL, this entity must be deleted from the database.
- DeleteRule(DeleteRule rule) - specifies the delete rule for the association.
ManyToManyAssociationConfiguration and ManyToManyAssociationConfiguration<TOtherEntity>
The ManyToManyAssociationConfiguration class has the following public methods:
- Name - specifies the association name.
- OtherKey - specifies the association properties on the other end of the association.
- OtherStorage - specifies non-public property or field for LinqConnect to work with instead of the navigation property on the other end of the association.
- LinkTableName - specifies the intermediate link table of the many-to-many association.
- LinkThisColumnNames - names of the foreign key columns from the foreign key, referencing the table of the entity, for which the Association() method was called.
- LinkOtherColumnNames - names of the foreign key columns from the foreign key, referencing the table of the other entity.