I need an attribute or a fluent method to set the default OrderBy to a property to avoid to have to add the OrderBy clause each time I use an Include.
public class ItemsGroup : BaseEntity
{
public virtual List<ItemDefinition> ItemDefinitions { get; set; }
...
}
public class ItemDefinition: BaseEntity
{
...
public int Position { get; set; }
}
I want to add an attribute like that
[DefaultOrderBy(nameof(ItemDefinition.Position), Sorting.Asc)]
public virtual List<ItemDefinition> ItemDefinitions { get; set; }
or something like that :
modelBuilder.Entity<ItemsGroup>().Property(ig => ig.ItemDefinitions).DefaultOrderBy(id => id.Position, Sorting.Asc);
I saw some interesting workaround like this for EF with interceptors and visitors but I can't reproduce it with EF core.
Is there a way to do something like that with EF core?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…