Developer technologies | .NET | Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm trying to set the model as below,
public class Person
{
[Key]
public int PersonId { get; set; }
public string Name { get; set; }
public List<Person> Friends { get; set; }
public List<Person> Enemies { get; set; }
}
But by default, ef core does not create such relations as I would like,
Default ef core create two tables:
CREATE TABLE `persons` (
`PersonId` int(11) NOT NULL AUTO_INCREMENT,
`Name` longtext,
PRIMARY KEY (`PersonId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
and
CREATE TABLE `personperson` (
`EnemesPersonId` int(11) NOT NULL,
`FriendsPersonId` int(11) NOT NULL,
PRIMARY KEY (`EnemesPersonId`,`FriendsPersonId`),
KEY `IX_PersonPerson_FriendsPersonId` (`FriendsPersonId`),
CONSTRAINT `FK_PersonPerson_Persons_EnemesPersonId` FOREIGN KEY (`EnemesPersonId`) REFERENCES `persons` (`PersonId`) ON DELETE CASCADE,
CONSTRAINT `FK_PersonPerson_Persons_FriendsPersonId` FOREIGN KEY (`FriendsPersonId`) REFERENCES `persons` (`PersonId`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
I would expect three tables
How can I solve this problem
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.