Код: Выделить всё
TextField
Вот упрощенная версия моих моделей:
Код: Выделить всё
public class Component : BaseEntity
{
public Guid Id { get; set; }
public required string Name { get; set; }
public ICollection Fields { get; set; } = [];
}
public abstract class Field
{
public Guid Id { get; set; }
public required string Name { get; set; }
public FieldType Type { get; set; }
public Guid ComponentId { get; set; }
public Component? Component { get; set; }
}
public class TextField : Field
{
public int? MaxLength { get; set; }
public bool IsMultiline { get; set; }
}
public class NumberField : Field
{
public decimal? MinValue { get; set; }
public decimal? MaxValue { get; set; }
}
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity(builder =>
{
builder
.HasDiscriminator(f => f.Type)
.HasValue(FieldType.Text)
.HasValue(FieldType.Number)
.HasValue(FieldType.OpenList);
});
builder.Entity(builder =>
{
builder.Property(t => t.MaxLength).HasColumnName("MaxLength");
builder.Property(t => t.IsMultiline).HasColumnName("IsMultiline");
});
builder.Entity(builder =>
{
builder.Property(n => n.MinValue).HasColumnName("MinValue");
builder.Property(n => n.MaxValue).HasColumnName("MaxValue");
});
}
< /code>
Проблема:
Мне нужно запросить все поля объекта компонента и получить унаследованные модели (TextField
Вопрос:
Как я могу запросить все поля объекта компонента и получить унаследованные модели с их конкретными свойствами в EF Core? Есть ли лучшие практики или альтернативные подходы для обработки этого сценария?
Подробнее здесь: https://stackoverflow.com/questions/793 ... ance-model