I’m trying to create a new table that has 2 foreign keys into another table. I’ve done this before and didn’t have any trouble, but now when I try to create the migration, I’m getting the following error:
$ dotnet ef migrations add RequestLedger
Build started…
Build succeeded.
Unable to create a ‘DbContext’ of type ”. The exception ‘Unable to determine the relationship represented by navigation ‘RequestLedger.NewStatus’ of type ‘RequestStatusType’. Either manually configure the relationship, or ignore this property using the ‘[NotMapped]’ attribute or by using ‘EntityTypeBuilder.Ignore’ in ‘OnModelCreating’.’ was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
The relevant parts of my cs files are:
RequestLedger.cs:
public long OldStatusId { get; set; }
public long NewStatusId { get; set; }
public virtual RequestStatusType OldStatus { get; set; } = null!;
public virtual RequestStatusType NewStatus { get; set; } = null!;
RequestLedgerEntityTypeConfiguration.cs:
builder.HasOne(d => d.OldStatus)
.WithMany(p => p.OldRequestLedgers)
.HasForeignKey(d => d.OldStatusId)
.OnDelete(DeleteBehavior.Restrict);
builder.HasOne(d => d.NewStatus)
.WithMany(p => p.NewRequestLedgers)
.HasForeignKey(d => d.NewStatusId)
.OnDelete(DeleteBehavior.Restrict);
RequestStatusType.cs:
OldRequestLedgers = new HashSet<RequestLedger>();
NewRequestLedgers = new HashSet<RequestLedger>();
public virtual ICollection<RequestLedger> OldRequestLedgers { get; set; }
public virtual ICollection<RequestLedger> NewRequestLedgers { get; set; }
What am I missing here?