Using EF code first want to control the name of the genereted column WHEN REFERENCING SELF. Tried [ForeignKey] and [Column] attributes. [Column] does not work and [ForeignKey] forces a relationship that seems to cause a problem. I have used [ForeignKey] attribute to set the name of a column in another class/table connected to this one.
Have
public class Episodes
{
public long ID {get; set;}
// ... other properties
public List<Episodes> Children { get; set; }
}
want a table (ID, …, ParentID) – get a table (ID, …, Episode_ID)
If you don’t have the foreign key column exposed as property in your entity class you can define the column name only with Fluent API:
I assume that the parent is optional (
ParentIDis a nullable column in the DB table) because, I guess, there should be some “root” in the tree, i.e. an episode that doesn’t have a parent anymore, hence at least for this episode theParentIDcolumn must beNULL.