1

尝试对 RavenDB 运行特定查询时出现以下错误:

Can't extract value from expression of type: ArrayIndex

这是生成错误的查询:

people = from p in RavenSession.Query<DBObjects.Person, People_ByNameAndTrashedSortByFirstNameAndLastName>()
         orderby p.FirstName, p.LastName
         select p;
...
//building LINQ query
...
people = from p in people
         where ((p.FirstName.StartsWith(SearchWords[0])) && (p.LastName.StartsWith(SearchWords[1])))
         select p;
...
//later
foreach(DBObject.Person person in people)  //triggers error listed above
{
}

我想知道这是否是 RavenDB 的限制。我注意到,如果我&&用切换||,那么我不会收到错误。当然,我也没有得到我想要的结果。我也尝试将查询重写为:

people = from p in people
         where p.FirstName.StartsWith(SearchWords[0])
         where p.LastName.StartsWith(SearchWords[1])
         select p;

我犯了同样的错误。

我也尝试过使用动态索引而不是静态索引。我犯了同样的错误。

4

1 回答 1

2

我想也许 RavenDB LINQ 驱动程序无法处理从查询中的数组中提取值。尝试将已经提取的值放在SearchWords[0]and的位置SearchWords[1]

var pref1 = SearchWords[0];
var pref2 = SearchWords[1];
... where ( p.FirstName.StartsWith(pref1) && p.LastName.StartsWith(pref2) )
于 2013-04-30T06:46:44.410 回答