首页 > 解决方案 > 配置实体中属性的实体框架核心默认排序

问题描述

我有一些他们拥有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在调用时使用,但我想将其作为全局解决。

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

标签: c#sortingentity-framework-core

解决方案


推荐阅读