I know variants of this question have been asked before (even by me), but I still don\'t understand a thing or two about this...
It was my understanding that one cou
You can also use a predefined index with the Stream
method. You may use a Where clause on indexed fields.
var query = session.Query();
var query = session.Query().Where(x => !x.IsDeleted);
using (var enumerator = session.Advanced.Stream(query))
{
while (enumerator.MoveNext())
{
var user = enumerator.Current.Document;
// do something
}
}
Example index:
public class MyUserIndex: AbstractIndexCreationTask
{
public MyUserIndex()
{
this.Map = users =>
from u in users
select new
{
u.IsDeleted,
u.Username,
};
}
}
Documentation: What are indexes? Session : Querying : How to stream query results?
Important note: the Stream
method will NOT track objects. If you change objects obtained from this method, SaveChanges()
will not be aware of any change.
Other note: you may get the following exception if you do not specify the index to use.
InvalidOperationException: StreamQuery does not support querying dynamic indexes. It is designed to be used with large data-sets and is unlikely to return all data-set after 15 sec of indexing, like Query() does.