功能不起作用,无法发送到RavenDB进行查询

时间:2017-01-05 08:59:05

标签: indexing ravendb

查询代码:

var query = session.IndexQuery<App_OrgSearch.IndexResult, App_OrgSearch>();
var organizationUnitResults = query.Statistics(out stats)
                    .Skip(0)
                    .Take(5)
                    .AsProjection<Org>().ToList();

public static IRavenQueryable<TResult> IndexQuery<TResult, TIndex>(this IDocumentSession session)
            where TIndex : AbstractIndexCreationTask, new()
        {
            return session.Query<TResult, TIndex>();
        }

App_OrgSearch是我定义的索引如下:

public class App_OrgSearch : AbstractIndexCreationTask<Org, App_OrgSearch.IndexResult>
    {
        public class IndexResult
        {
            public string Id { get; set; }
            public string BusinessName { get; set; }
            public string ShortName { get; set; }
            public IList<string> Names { get; set; }
            public List<string> PhoneNumbers { get; set; }
            public List<OrganizationUnitPhone> OrganizationUnitPhones { get; set; }
        }

        public App_OrganizationUnitSearch()
        {
            Map = docs => from doc in docs
                select new
                {
                    Id = doc.Id,
                    Names = new List<string>
                    {
                        doc.BusinessName,
                        doc.ShortName,
                    },
                    BusinessName = doc.BusinessName,
                    ShortName = doc.ShortName,
                    PhoneNumbers = doc.OrganizationUnitPhones.Where(x => x != null && x.Phone != null).Select(x => x.Phone.Number),

                };

            Indexes.Add(x => x.Names, FieldIndexing.Analyzed);
        }
    }

我在数据库中有27条记录。我想取5,但查询后,返回所有27条记录。为什么Take功能不起作用?

1 个答案:

答案 0 :(得分:0)

您的示例代码似乎有误。

var query = session.IndexQuery<App_OrgSearch.IndexResult, App_OrgSearch>();
var organizationUnitResults = organizationUnitsQuery.Statistics(out stats)

什么是organizationUnitsQuery?您的查询为query,但会话中没有IndexQuery方法