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; }
}
Just use your original
IEntityKeyinterface, with aTupleasTKey:As a side note, it seems to me that
PlayerTeamis not an entity but merely an association…