2

I have defined an index with the following syntax:

public class TestCasesForConfigurationModeIndex 
      : AbstractIndexCreationTask<TestCase>
{
     TestCasesForConfigurationModeIndex() 
     {
         Map = docs => from x in docs select new { x.CurrentName }
         Indexes.Add(x => x.CurrentName, FieldIndexing.Analyzed); 
         TransformResults = ... select new TestCaseForConfigurationMode { ... }
     }
}

Querying this index via the Raven Studio works as expected, but how can I perform the same query using the LINQ API? The problem is that the "As" extension method is not availble for IDocumentQuery, but only for var query = _db.Advanced.LuceneQuery() .As().ToArray();

I also tried something like the following:

var results = _db.Advanced.LuceneQuery<TestCase, TestCasesForConfigurationModeIndex>()
     .WhereEquals(x => x.CurrentName, searchExpression).Fuzzy((decimal)0.5);
     .AsQueryable().As<TestCaseForConfigurationMode>().ToArray();

This kind of works (the server console shows me "Results: 7 returned out of 7 total." which is correct), but I don't get any results back (empty array).

4

3 回答 3

3

您可以使用SelectFields<>,例如:

Session.Advanced.LuceneQuery<IndexModel, Index>()
    .Where("Name:(Bill) ...")
    .SetResultTransformer("MyResultTransformer")
    .SelectFields<MyResultTransformer.Result>()
    .ToList();

确保在单独的类中有结果转换器(本例中为 MyResultTranformer)

于 2013-08-30T15:03:10.557 回答
0

您可能需要使用:

 using Raven.Client.Linq; 

导入 As 扩展方法。

于 2013-01-06T07:58:26.603 回答
-1

尝试使用.OfType<T>()而不是.As<T>(). 它们是相同功能的同义词。

此外,您不一定需要转换结果才能使用它(取决于您在做什么)。

于 2013-01-06T16:01:37.363 回答