Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Tracked by #22952
AndriySvyryd opened this issue Jul 6, 2020 · 2 comments · Fixed by #25357
Closed
Tracked by #22952

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

AndriySvyryd opened this issue Jul 6, 2020 · 2 comments · Fixed by #25357
Labels
area-conventions area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@AndriySvyryd
Copy link
Member

AndriySvyryd commented Jul 6, 2020

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.

@smitpatel
Copy link
Member

Also consider overloads in #21505 (comment)

@AndriySvyryd wrote
To clarify, the only required overloads are:

EntityTypeBuilder UsingEntity(
    [NotNull] name,
    [NotNull] Func<EntityTypeBuilder, ReferenceCollectionBuilder> configureRight,
    [NotNull] Func<EntityTypeBuilder, ReferenceCollectionBuilder> configureLeft);

EntityTypeBuilder<TLeftEntity> UsingEntity(
    [NotNull] name,
    [NotNull] Func<EntityTypeBuilder, ReferenceCollectionBuilder> configureRight,
    [NotNull] Func<EntityTypeBuilder, ReferenceCollectionBuilder> configureLeft,
    [NotNull] Action<EntityTypeBuilder> configureAssociation);

If the specified name doesn't match any existing entity type then we'll assume the CLR type to be Dictionary<string, object> and create a new entity type

@softlion
Copy link

softlion commented Apr 9, 2021

Can we have a sample plz ?

AndriySvyryd added a commit that referenced this issue Jul 29, 2021
@AndriySvyryd AndriySvyryd added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed needs-design labels Jul 29, 2021
@AndriySvyryd AndriySvyryd removed their assignment Jul 29, 2021
AndriySvyryd added a commit that referenced this issue Jul 30, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0, 6.0.0-rc1 Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-conventions area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants