c# - 配置实体中属性的实体框架核心默认排序
问题描述
我有一些他们拥有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
在调用时使用,但我想将其作为全局解决。
我研究了很多,但我没有找到。有没有这样的解决方案?我该怎么做?你还有什么好主意吗?
解决方案
推荐阅读
- javascript - 如何在单击输入类型提交后使页面不重新加载并且不打开php页面?
- javascript - async / await 链接何时停止?
- java - XML cardView 阻塞了它下面的 recyclerView 的上半部分
- c# - 如何使用服务帐户发出 Google Home Graph 请求?
- arrays - 使用 fscanf 填充结构体数组
- android - Visual Studio 下的 Android Activity 在引用 .a 库时尝试构建时导致“未定义的引用”
- c - 我的 C 程序无法识别有效输入,认为这是因为换行问题
- ruby-on-rails - 这是在后端允许在 Rails 中使用参数的安全方法吗?
- python - *不*能够从文件中取回值
- svelte-3 - svelte 不断更新 store var 而不点击更新