I have a problem in my project. In one database relations have a join to self with many to many.
What any of people solve this problem in Entity FrameWork?
I have a problem in my project. In one database relations have a join to self with many to many.
What any of people solve this problem in Entity FrameWork?
Any many-to-many relationship should create a new table to represent the pairings.
Example: say you have a table People
, and you want to show who gave birthday gifts. A person can give gifts to many friends, and a person may receive gifts from many other people.
CREATE TABLE People (person_id INT PRIMARY KEY);
CREATE TABLE GiftGiving (
from_person_id INT,
to_person_id INT,
PRIMARY KEY (from_person_id, to_person_id),
FOREIGN KEY (from_person_id) REFERENCES People(person_id),
FOREIGN KEY (to_person_id) REFERENCES People(person_id)
);
Re your comment:
For EF implementations, see these related questions:
I simply put an ICollection to itself. Let EF handle the db layer. public class Person{ public virtual ICollection OtherPersons {get;set;} }