3

Maybe it's simple question, but does AsQueryable() have some performance loss?

Generally speaking we are working with RavenDB and we have existing code like this

protected override IQueryable<T> QueryableIndexRawQuery(string rawQuery, int skip = 0, int take = 128, string indexName = null) 
{ 
    var defaultIndexName = !string.IsNullOrWhiteSpace(indexName) ? indexName : string.Format("{0}{1}", typeof(T).Name, IndexPreffix);

    return this.Session.Advanced.DocumentStore.DatabaseCommands.GetIndex(defaultIndexName) != null 
        ? this.Session.Advanced.LuceneQuery<T>(defaultIndexName).Statistics(out this.Statistics).Skip(skip).Take(take).Where(rawQuery).AsQueryable()
        : this.Session.Advanced.LuceneQuery<T>().Statistics(out this.Statistics).Skip(skip).Take(take).Where(rawQuery).AsQueryable();
}

So Where clause return us IDocumentQuery then we try to represent it AsQueryable()

this.Session.Advanced.LuceneQuery<T>(defaultIndexName).Statistics(out this.Statistics).Skip(skip).Take(take).Where(rawQuery)

The question what AsQueryable() eventually does internally? How does it convert it? Answers with in-memory collection examples like List<> will be really useful as well.

Like this:

    var list = new List<string>() { "1", "2", "3" };
    list.AsQueryable();
Jevgenij Nekrasov
  • 2,690
  • 3
  • 30
  • 51
  • This is complicated, but it's [explained somewhat by Jon Skeet on this page](http://msmvps.com/blogs/jon_skeet/archive/2011/02/20/reimplementing-linq-to-objects-part-43-out-of-process-queries-with-iqueryable.aspx). – Matthew Watson Apr 15 '13 at 12:05

1 Answers1

1

.AsQueryable() forces us to evaluate the query in memory, since you are using session.Advanced.LuceneQuery(). This is NOT recommended. You need to use session.Query() if you want to use IQueryable.

Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41
  • Ok, we are LuceneQuery because we need to server side filtering, which is pretty completecated. For example, how can we do such filtering with session.Query() - var query = _session.Advanced.LuceneQuery().Where("(Name:(*ontra*)) AND (LabelKey:(*ontra*)) OR (DescriptionKey:(*ontra*) AND (LabelKey: (*tra*)))").ToList(); We can use Search() method, but it is not suitable for composite conditions. Maybe it is another question, but the initial one was raised by it. – Jevgenij Nekrasov Apr 16 '13 at 07:53