实体框架核心配置实体中属性的默认排序

时间:2021-07-06 08:40:38

标签: c# sorting entity-framework-core

我有一些实体,它们具有 Priority 属性。我想为配置中的实体配置默认排序。其中一个实体如下所示:

public class Country
{
   public int Id {get; set;}
   public string Name {get; set;}
   public int Priority {get; set;}
}

我也有实体的 Config 类。我使用 Fluent API 进行配置

public class CountryConfig : IEntityTypeConfiguration<Country>
{
   public virtual void Configure(EntityTypeBuilder<Country> builder)
   {
      builder.Property(x => x.Id).HasColumnName("ID");
      builder.Property(x => x.Name).HasColumnName("NAME");
      builder.Property(x => x.Priority).HasColumnName("PRIORITY");

      builder.Property(x => x.Priority).HasDefaultSortAsc(); // there is no `HasDefaultSortAsc` 
   }
}

没有HasDefaultSortAsc方法。我想像它或类似的那样配置默认排序。我可以在调用时使用 OrderBy,但我想将其解决为全局。

我研究了很多,但没有找到。 有类似的解决方案吗?我该怎么做?你还有什么好主意吗?

0 个答案:

没有答案