尝试针对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;
我得到同样的错误。
我也尝试使用动态索引而不是静态索引。我得到了同样的错误。
答案 0 :(得分:2)
我想也许RavenDB LINQ驱动程序无法处理从查询中的数组中提取值。尝试将已提取的值放在SearchWords[0]
和SearchWords[1]
的位置:
var pref1 = SearchWords[0];
var pref2 = SearchWords[1];
... where ( p.FirstName.StartsWith(pref1) && p.LastName.StartsWith(pref2) )