Skip to content

FKs for self-referencing tables not created #63

Description

@dsav

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".

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions