What kind of fallout can I expect from manually removing the foreign key constraint generated in EF Core?
We are trying to normalize a table to be used on multiple tables in our system below is a brief example.
Entities:
public class Note
{
public Guid? MasterId { get; set; }
public string? MasterType { get; set; } = string.Empty;
public UserValueObject User { get; private set; }
public string Content { get; private set; }
//Removed for simplicity
}
public class Quote
{
public Branch Branch { get; private set; }
public ICollection<Note>? Notes { get; private set; } = new List<Note>();
//Removed for simplicity
}
public class Lead
{
public DateTime? DateConverted { get; set; }
public Branch Branch { get; private set; }
public LeadStatus Status { get; private set; }
public ICollection<Note>? Notes { get; private set; } = new List<Note>();
//Removed for simplicity
}
EF Entity Configurations
public void Configure(EntityTypeBuilder<Quote> builder)
{
//Simlified
builder.HasMany(x => x.Notes)
.WithOne()
.HasForeignKey(x => x.MasterId)
.IsRequired(false)
.OnDelete(DeleteBehavior.NoAction);
}
public void Configure(EntityTypeBuilder<Lead> builder)
{
//Simlified
builder.HasMany(x => x.Notes)
.WithOne()
.HasForeignKey(x => x.MasterId)
.IsRequired(false)
.OnDelete(DeleteBehavior.NoAction);
}
The above configurations always generate a Foreign Key Constraint even following the example on (without the navigation property) MS EF Docs