Создание динамической формы c, в которой пользователь может создавать сущности и их поля. Возможный dataTypeId из EntityField может быть EntityId, так что поиск может быть Entity.
public class Entity : Base, IBase
{
public Entity()
{
EntityFields = new HashSet<EntityField>();
PickFromEntity = new HashSet<EntityField>();
}
public Guid Id { get; set; }
[StringLength(255)]
[Required(AllowEmptyStrings = false)]
[Remote("CheckDuplicate", "Entity", HttpMethod = "POST")]
public string Name { get; set; }
public virtual ICollection<EntityField> EntityFields { get; set; }
public virtual ICollection<EntityField> PickFromEntity { get; set; }
}
public class EntityField : Base, IBase
{
public EntityField()
{
EntityChildren = new HashSet<Entity>();
}
public Guid Id { get; set; }
public Guid EntityId { get; set; } //Field for What Entity
[StringLength(255)]
[Required(AllowEmptyStrings = false)]
public string Name { get; set; }
[StringLength(1000)]
public string HelpDescription { get; set; }
public short Order { get; set; }
public Guid DataTypeId { get; set; }
public Nullable<Guid> PickListId { get; set; } //if DAtatype is Picklist
public Nullable<Guid> PickFromEntityId { get; set; } //if DAtatype is Entity
public Nullable<int> Minimum { get; set; } //Will ast as Total rows for Data Type Table
public Nullable<int> Maximum { get; set; } //Will ast as Total Columns for Data Type Table
public bool IsVisibleOnSelect { get; set; } = false; //Only for Entity Data Type
public bool IsRequired { get; set; } = false;
public string Format { get; set; }
public string DefaultValue { get; set; }
[ForeignKey("PickFromEntityId")]
public virtual Entity PickFromEntity { get; set; }
[ForeignKey("PickListId")]
public virtual PickList PickList { get; set; }
[ForeignKey("EntityId")]
public virtual Entity Entity { get; set; }
[ForeignKey("DataTypeId")]
public virtual ListOfValue DataType { get; set; }
public ICollection<Entity> EntityChildren { get; set; }
}
Миграция выдает ошибку: Невозможно определить отношение, представленное свойством навигации 'Entity.PickFromEntity' типа 'ICollection ». Либо настройте отношение вручную, либо игнорируйте это свойство с помощью атрибута [NotMapped] или с помощью EntityTypeBuilder.Ignore в OnModelCreating.