Как может быть отношение с отношением «один ко многим» в одной таблице с ядром структуры сущностей 2.2.4?Я использовал свободный API для создания отношения внешнего ключа
public class Animal
{
[Key]
public string AnimalId { get; set; }
public int CategoryId { get; set; }
public DateTime BirthDate { get; set; }
public string FatherId { get; set; }
public string MotherId { get; set; }
public int GenotypeId { get; set; }
#region Foreign Key
public Genotype Genotype { get; set; }
public ICollection<Animal> Animals { get; set; }
public Animal FatherAnimal{ get; set; }
public Animal MotherAnimal{ get; set; }
public AnimalCategory AnimalCategory { get; set; }
#endregion
}
Свободный API:
builder.HasOne<Animal>(s => s.FatherAnimal)
.WithMany(a => a.Animals)
.HasForeignKey(s => s.FatherId ).OnDelete(DeleteBehavior.Cascade);
builder.HasOne<Animal>(s => s.MotherAnimal)
.WithMany(a => a.Animals)
.HasForeignKey(s => s.MotherId ).OnDelete(DeleteBehavior.Cascade);
Невозможно создать отношения между Animal.Animals и Animal.MotherAnimal, потому что там уже естьэто связь между Animal.Animals и Animal.FatherAnimal.Свойства навигации могут участвовать только в одном отношении.