Is there a way in the IEntityTypeConfiguration to add a where clause to the collection. As a simple (incomplete) example, I would like the Form.Items to only include the FormItems which have the FormId equal to the Form and ParentFormItemId equal to null.
public class Form
{
public Guid FormId { get; set; }
public List<FormItem> Items { get; set; }
}
public class FormItem
{
public Guid FormItemId { get; set; }
public Guid FormId { get; set; }
public virtual Form Form { get; set; }
public Guid? ParentFormItemId { get; set; }
public List<FormItem> Children { get; set; }
}
public class FormConfiguration : IEntityTypeConfiguration<Form>
{
public void Configure(EntityTypeBuilder<Form> builder)
{
builder.HasKey(u => u.FormId);
builder
.HasMany(x => x.Items)
.WithOne(c => c.Form);
}
}
so essentially is there a way to do something like
builder
.HasMany(x => x.Items)
.WithOne(c => c.Form)
.Where(x => x.ParentFormId == null);
Form.Items would then only include the parent FormItems linked to that form, rather all the items linked to that form.
Thanks