[英]How to deal with sorting for multiple Language in MongoDb asp.net core application using mongoDb C# driver
I have a collection in which title can be in multiple language我有一个集合,其中的标题可以是多种语言
example: If my Platform language is Spanish all the titles will be in Spanish.例如:如果我的平台语言是西班牙语,则所有标题都是西班牙语。 so how can I sort with Title
那么我如何用标题排序
public class Collection
{
public string Id { get; set; }
public string Title { get; set; }
}
there are two Ways to sort,有两种排序方式,
for both cases you have to use AggregateOptions and Set Collation.Local to your desired local, you can toggle other flags to get your appropriate case sorting as well.对于这两种情况,您都必须使用AggregateOptions并将Collation.Local设置为所需的本地,您还可以切换其他标志以获得适当的案例排序。
collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}
For MongoDb Linq对于 MongoDb Linq
var option = new AggregateOptions
{
Collation = new Collation(searchParam.Local, false)
};
var list = collection.AsQueryable(option).OrderBy(x=>x.Title).
ToListAsync(ct);
For Fluent Aggregate Syntax对于 Fluent 聚合语法
var option = new AggregateOptions
{
Collation = new Collation(searchParam.Local, false)
};
var result collection.Aggregate(option).Match(searchFilter).
Sort(Builders<Collection>.Sort.Ascending(x=>x.Title).
ToListAsync(ct);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.