当在编译时不知道术语时,是否有推荐的方法来使用 StartsWith 搜索多个术语中的每一个?
我设想这样的事情:
var searchTerms = "John Doe".Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
var query = session.Query<Person, PersonIndex>()
.Where(x => x.FirstName.StartsWithAnyOf(searchTerms) ||
x.LastName.StartsWithAnyOf(searchTerms));
该查询相当于:
var query = session.Query<Person, PersonIndex>()
.Where(x => x.FirstName.Starts(searchTerms[0]) ||
x.LastName.StartsWith(searchTerms[0]) ||
x.FirstName.Starts(searchTerms[1]) ||
x.LastName.StartsWith(searchTerms[1]));
是在运行时(PredicateBuilder 或类似)构建 LINQ 查询的答案吗?