C
C#3y ago
adnan307

❔ ef core foreign key problem

public class Player
{
public int Id { get; set; }
public Ban Ban { get; set; }
}

public class Ban
{
public int Id { get; set; }
public Player Player { get; set; }
public Player Admin { get; set; }
}
public class Player
{
public int Id { get; set; }
public Ban Ban { get; set; }
}

public class Ban
{
public int Id { get; set; }
public Player Player { get; set; }
public Player Admin { get; set; }
}
how i need to configure the foreign keys for this situation?
4 Replies
Saber
Saber3y ago
well I would expect that the Player entity would have 2 lists, one to represent the bans the player has recieved, and one to represent the bans they've given out. public List<Ban> Bans {get;set;} and public List<Ban> GivenBans {get;set;} then to configure it
adnan307
adnan307OP3y ago
is there a solution without the lists?
Angius
Angius3y ago
I'd say configure them on the Ban entity And configure the relationship with .HasOne(...).WithOne(...)
Accord
Accord3y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?