What are the tradeoffs between using an object identifier and adding objects to other classes?

EDIT: the great early answers made me realize that my question regarding trade-offs would be more useful given the variation of @Leo.

I am developing a data model in Code-First EF and I feel unsure of what is probably quite fundamental.

Given the Team and Player classes in which the team has N players, a data model can be developed

1) either with the objects of the players players:

class Team
{
    int Id;
    ICollection<Player> Players;
}

or 2) (REFUSED TO HAVE AN INSUFFICIENT ADVANTAGE), we can simply pass the link identifier to the players

class Team
{
    int Id;
    ICollection<int> PlayerIds;
}

or 3) implemented with a foreign key identifier for an independent model

class Team
{
    int Id;
}

class Player
{
    int Id;
    int TeamId;
}

, @Leo. , , , " 1"?

+4
4

, , , , , / . , , , , , , , ( ) . , , , , , , , . , , . , ...

class Team
{
    int Id;
    ICollection<Player> Players;
}

, IF ( ) , . , , , / Team...

class Team
{
    int Id;
    string TeamName;
}

class Player
{
    int Id;
    int TeamId;
}

, , ... , / , , 2 ( ... ), , 2 .

, 1 , , , Player, . , API, . , , ... ( ) , .

" 1"?

, , , , , .

+3

, - . , , - , , .

0

Id, . , .

. .

, Id . () , , . .

0

-, : .

Entity Framework

  • , .

    class Player
    {
        int Id;
        Team Team;
    }
    
  • , :

    class Player
    {
        int Id;
        [ForeignKey("Team")]
        int TeamId;
        Team Team;
    }
    

2) , . , ? .

, DDD, , . , , EF. :

, Team, TeamId. , Team , . TeamId (, ). , Team, . Id .

TeamId, , . . Team. , Team Player ? Team, Id, Player TeamId Player, TransactionScope. FK , player.Team = team, EF , FK.

So, I'm trying to say that DDD principles such as loosening communication, separation of problems play a role in the background at best, when it comes to optimizing a class model, which serves as a conceptual model for the Entity Framework. This class model is not a domain model; it is a data layer in the first place .

0
source

Source: https://habr.com/ru/post/1528018/


All Articles