Skip to content

Non standard id property #798

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

Closed
wants to merge 5 commits into from
Closed

Non standard id property #798

wants to merge 5 commits into from

Conversation

ClintGood
Copy link

@ClintGood ClintGood commented Aug 9, 2020

Closes #797

Draft PR

This adds support for an [Id] attribute. This can decorate a property of an entity, allowing it to use a name other than "Id"
If an Id property is not specified, it will fallback to the standard "Id" property

To support for HasManyThrough relationships with foreign key property names other than "EntityNameId", the [HasManyThrough] attribute may specify LeftIdPropertyName and RightIdPropertyName values. If not specified it will fallback to standard "EntityNameId"

A number of additional entities in the JsonApiDotNetCoreExample demonstrate these features
Player, Team, TeamPlayer, Award, PlayerAward, Championship, demonstrate HasOne, HasMany and HasManyThrough using non standard key property names.

public class Player: IIdentifiable<Guid>
{
    // Non standard id property
    [Id]
    public Guid PlayerId { get; set; }

    // Non standard HasManyThrough related property names
    [NotMapped]
    [HasManyThrough(nameof(PlayerAwards), nameof(PlayerAward.RecipientNo), nameof(PlayerAward.AwardNo))]
    public ISet<Award> Awards { get; set; }
    public ISet<PlayerAward> PlayerAwards { get; set; }
     ...

Be gentle. First PR. Constructive criticism appreciates. Based on bart-degreed:complex-queries. Only a modest number of changes if that is accepted first.

FEATURE

  • write tests that address the requirements outlined in the issue
  • fulfill the feature requirements
  • bump package version

RELATED REPOSITORY UPDATES

  • does this feature require documentation? if so, open an issue in the docs repo
  • does this feature break an API that is implemented in the templates repository? if so, open an issue

Bart Koelman and others added 5 commits July 6, 2020 11:01
@ClintGood ClintGood closed this Aug 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Support models with key fields other than "Id"
1 participant