Мы пытаемся нормализовать таблицу, которая будет использоваться в нескольких таблицах в нашей системе ниже. это краткий пример.
Объекты:
Код: Выделить всё
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? Notes { get; private set; } = new List();
//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? Notes { get; private set; } = new List();
//Removed for simplicity
}
Код: Выделить всё
public void Configure(EntityTypeBuilder builder)
{
//Simlified
builder.HasMany(x => x.Notes)
.WithOne()
.HasForeignKey(x => x.MasterId)
.IsRequired(false)
.OnDelete(DeleteBehavior.NoAction);
}
public void Configure(EntityTypeBuilder builder)
{
//Simlified
builder.HasMany(x => x.Notes)
.WithOne()
.HasForeignKey(x => x.MasterId)
.IsRequired(false)
.OnDelete(DeleteBehavior.NoAction);
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... oreign-key
Мобильная версия