Foreign keys for self-referencing tables are not created.
For example, have a look at this entity:
public class EventInfo
{
public int Id { get; set; }
public virtual ICollection<EventInfo> ChildEventInfos { get; set; }
public int? ParentEventInfoId { get; set; }
public virtual EventInfo ParentEventInfo { get; set; }
}
and this configuration of it:
modelBuilder.Entity<EventInfo>()
.HasOptional(x => x.ParentEventInfo)
.WithMany(x => x.ChildEventInfos)
.HasForeignKey(x => x.ParentEventInfoId);
Created table lacks FK ParentEventInfoId REFERENCES EventInfo (Id).
The problem seems to be in CreateDatabaseStatementBuilder.GetCreateTableStatements, where respective association type is filtered out since its Constraint.RoleTo.Name is "EventInfoSelf", not "EventInfo".
Foreign keys for self-referencing tables are not created.
For example, have a look at this entity:
public class EventInfo { public int Id { get; set; } public virtual ICollection<EventInfo> ChildEventInfos { get; set; } public int? ParentEventInfoId { get; set; } public virtual EventInfo ParentEventInfo { get; set; } }and this configuration of it:
Created table lacks FK
ParentEventInfoId REFERENCES EventInfo (Id).The problem seems to be in
CreateDatabaseStatementBuilder.GetCreateTableStatements, where respective association type is filtered out since itsConstraint.RoleTo.Nameis"EventInfoSelf", not"EventInfo".