I have a class called human that has an attribute called friends from which is a list of type human. Actually, I am going to create a many-to-many relationship between the human class and itself.
How can you create a special table for this relationship in SQL Server using Entity Framework and Codefirst (It is preferable not to use Fluent API)?
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public List<Person> Friends { get; set; }
}
I tried Codefirst, but the table for many-to-many relationships in the SQL Server database was not created. The only thing that happened was creating a column in SQL Server called Person_ID. It seems to create only a one-to-one relationship.
SQL Server Datatable of Person:
ID | Name | Person_ID |
---|---|---|
NULL | NULL | NULL |
Saber Safdari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.