Skip to content

Add overloads of UsingEntity() that take advantage of conventions #21535

@AndriySvyryd

Description

@AndriySvyryd

We don't need this for 5.0, but it would be nice to add some sugar.

Each overload will have a version that takes a Type, a version that takes a name and a version that take neither (we'll assume the type is Dictionary<string, object> and generate the type name based on the related entity types). Also there'll be a version of each that returns the builder for the association entity type and one that takes it as a nested lambda as well as the non-generic flavor (~9 variations of each in total). I'll only show the Type with nested lambda overloads here for brevity.

EntityTypeBuilder<TLeftEntity> UsingEntity<TAssociationEntity>(
    [NotNull] Action<EntityTypeBuilder<TAssociationEntity>> configureAssociation);

We'll use the FKs found by convention if there's exactly one compatible FK to each of the entity types in the M2M. The PK will be configured as composite over those FKs, so in the simple case configureAssociation could be null

EntityTypeBuilder<TLeftEntity> UsingEntity<TAssociationEntity>(
    [NotNull] Action<ReferenceCollectionBuilder<TLeftEntity, TAssociationEntity>> configureRight,
    [NotNull] Action<ReferenceCollectionBuilder<TRightEntity, TAssociationEntity>> configureLeft,
    [NotNull] Action<EntityTypeBuilder<TAssociationEntity>> configureAssociation)

This one additionally allows to configure the FKs that we found. This version will throw immediately if the FKs are not found or are ambiguous.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions