让我们说我拥有以下EF核心实体:
public class Day : AuditEntity
{
public int Id { get; set; }
public bool IsGame { get; set; }
public GameDay? GameDay { get; set; }
public StoryDay? StoryDay { get; set; }
}
是否可以进行配置,以便如果IsGame为true,则需要GameDay,否则需要StoryDay?我以为您可以按照以下方式解决它:
public class DayConfiguration : IEntityTypeConfiguration<Day>
{
public void Configure(EntityTypeBuilder<Day> builder)
{
builder.Property(d => d.GameDay).IsRequired(d => d.IsGame)
}
}
但是显然IsRequired并不将函数作为参数。