Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6659903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:05:18+00:00 2026-05-26T02:05:18+00:00

I have 3 tables: Player => PlayerId (Primary Key), Name, etc Team => TeamId

  • 0

I have 3 tables:

Player => PlayerId (Primary Key), Name, etc  
Team => TeamId (Primary Key), Name, etc  
PlayerTeam => PlayerId, TeamId (The combination must be unique)  

then I have the following:

public interface IEntityKey<TKey>
{
    TKey Id { get; }    
}

public interface IRepository<TKey, TEntity> where TEntity : class, IEntityKey<TKey>
{
  IQueryable<TEntity> All();
  TEntity FindBy(Expression<Func<TEntity, bool>> expression);
  ....
  TEntity FindBy(TKey id);
}

Now while the above would work fine for tables with a single key such as the player or team table, how would I implement it for my playerteam table? What I need is a solution that would cater for any number of keys. I would prefer a solution such as …

public interface IEntityKey<TKey> where TKey : System.Tuple
{
    TKey Id { get; }    
}

over

public interface IEntityKey<TKey1, TKey2>
{
    TKey1 Id1 { get; }    
    TKey2 Id2 { get; }    
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:05:19+00:00Added an answer on May 26, 2026 at 2:05 am

    Just use your original IEntityKey interface, with a Tuple as TKey:

    public class PlayerTeam : IEntityKey<Tuple<int, int>>
    {
        Tuple<int, int> IEntityKey<Tuple<int, int>>.Id
        {
            get { return Tuple.Create(PlayerId, TeamId); }
        }
    
        public int PlayerId { get; set; }
        public int TeamId { get; set; }
    }
    

    As a side note, it seems to me that PlayerTeam is not an entity but merely an association…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 tables like this player(id,name,age,teamid) team(id,name,sponsor,totalplayer,totalchampion,boss,joindate) playerdetail(id,playerid,position,number,allstar,joindate) I want to select teaminfo
I have two tables in the database Team:Id(int PK), Name(nvarchar) and Player:Id(int PK), Name(nvarchar),
i have the following 4 tables: Participant {id_participant, etc.} Player {id_participant, name, phone, etc.}
In a table I have the following schema table1: playerID int primary key, nationalities
I have two tables Players table (object) ------------- PlayerID Name Birthday List<Matches> Matches and
I have the tables: Player Id : int - primarykey Name : string BowlerType
I have a table Player with columns id, name, wins, games_played. I mapped it
I have several tables whose only unique data is a uniqueidentifier (a Guid) column.
Given the following schema: CREATE TABLE players ( id BIGINT PRIMARY KEY, name TEXT
I have on table named players , then other tables named tries , conversions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.