Foreign key to the same table

asp.net-core asp.net-core-mvc c# entity-framework-core

Question

I'm trying users can comment publications. I've created the table Comments with EF Core.

There are multiple levels of comments and I've implmeneted the following way:

Table Publications

- Id (primary key)

Table Comments

- PublicationId (foreing key to Publication)
- Comment
- ParentComment (foreign key to Comments, that is, the same table)

The problem is an error warn me I can't créate a foreing key to the same table. How can I implement the hierarchy then?

1
1
7/27/2017 10:21:43 PM

Popular Answer

Your code is suppose to look something like this

public int Id {get; set;}
public virtual Publication Publication {get; set;} // If Publication is an object
public virtual Comment Comment {get; set;}
public virtual Comment ParentComment {get; set;}
1
7/27/2017 6:41:39 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow