Conventions: Querying

FindPropertyNameForIndex and FindPropertyNameForDynamicIndex

These two conventions specify functions that are used to find the indexed property name for a static index or a dynamic one. This can be useful when you are indexing nested properties of complex types. Their default implementations are:

FindPropertyNameForIndex = (indexedType, indexName, path, prop) =>
    (path + prop).Replace(",", "_").Replace(".", "_"),

FindPropertyNameForDynamicIndex = (indexedType, indexName, path, prop) => path + prop,

The arguments in the order of appearance: an indexed document type, an index name, a current path and a property path.

FindProjectionPropertyNameForIndex

This convention specifies a function that is used to find the projected property name for a static index.
This can be useful when you want to use a static index to project nested properties which are not Stored.

public Func<Type, string, string, string, string> FindProjectedPropertyNameForIndex

Same as in the two conventions above, the arguments in the order of appearance: an indexed document type, an index name, a current path and a property path.

By default FindProjectionPropertyNameForIndex is set to null.
When FindProjectionPropertyNameForIndex is null (or returns null), the FindPropertyNameForIndex convention is used instead.

Example

Consider we have the following index, and we want to project School.Id:

private class UsersIndex : AbstractIndexCreationTask<User>
{
    public UsersIndex()
    {
        Map = users => from user in users
            select new
            {
                SchoolId = user.School.Id
            };
    }
}

Without setting FindProjectedPropertyNameForIndex, FindPropertyNameForIndex will be used :

var query = session.Query<User, UsersIndex>()
    .Where(u => u.School.Id != null)
    .Select(u => u.School.Id)
    .ToList();
from index 'UsersIndex'
where School_Id != null
select School_Id

School_Id is indexed but not Stored, meaning that we will try to fetch School_Id from the document - which doesn't have this property.

Setting the FindProjectedPropertyNameForIndex convention can solve this issue:

Conventions =
{
    FindProjectedPropertyNameForIndex = (indexedType, indexName, path, prop) => path + prop
}

var query = session.Query<User, UsersIndex>()
    .Where(u => u.School.Id != null)
    .Select(u => u.School.Id)
    .ToList();
from index 'UsersIndex'
where School_Id != null
select School.Id

ThrowIfQueryPageSizeIsNotSet

Since RavenDB 4.0 there is no limitation for the number of results returned for a single query by the server. The ThrowIfQueryPageSizeIsNotSet convention decides whether RavenDB Client should prevent from executing queries if their page size is not explicitly set.

Enabling this configuration at development stage can be useful to pinpoint all the possible performance bottlenecks.

ThrowIfQueryPageSizeIsNotSet = true