1

Include使用此查询(使用而不是)时,我收到一个错误,提示我超出了每个会话允许的请求数(30 Customize):

ApplicationServer appServer = QuerySingleResultAndSetEtag(session => session
    .Include<ApplicationServer>(x => x.CustomVariableGroupIds)
    .Include<ApplicationServer>(x => x.ApplicationIdsForAllAppWithGroups)
    .Include<ApplicationServer>(x => x.CustomVariableGroupIdsForAllAppWithGroups)
    .Include<ApplicationServer>(x => x.CustomVariableGroupIdsForGroupsWithinApps)
    .Include<ApplicationServer>(x => x.InstallationEnvironmentId)
    .Load <ApplicationServer>(id))
    as ApplicationServer;

请注意,错误发生在此行,应用程序中的每个 AppWithGroup 都会调用该行:

appGroup.Application = QuerySingleResultAndSetEtag(session =>
    session.Load<Application>(appGroup.ApplicationId)) as Application;

但是,此查询(使用Customize)不会创建额外的请求:

ApplicationServer appServer = QuerySingleResultAndSetEtag(session =>
    session.Query<ApplicationServer>()
    .Customize(x => x.Include<ApplicationServer>(y => y.CustomVariableGroupIds))
    .Customize(x => x.Include<ApplicationServer>(y => y.ApplicationIdsForAllAppWithGroups))
    .Customize(x => x.Include<ApplicationServer>(y => y.CustomVariableGroupIdsForAllAppWithGroups))
    .Customize(x => x.Include<ApplicationServer>(y => y.CustomVariableGroupIdsForGroupsWithinApps))
    .Customize(x => x.Include<ApplicationServer>(y => y.InstallationEnvironmentId))
    .Where(server => server.Id == id).FirstOrDefault())
    as ApplicationServer;

但是,上面的查询会导致错误:

尝试仅通过 id 查询被阻止,您应该使用 call session.Load("applications/2017"); 而不是 session.Query().Where(x=>x.Id == "applications/2017");

您可以通过指定 documentStore.Conventions.AllowQueriesOnId = true; 来关闭此错误,但不建议这样做,仅出于向后兼容性的原因提供。

我必须设置AllowQueriesOnId = true,因为这是我可以让它工作的唯一方法。

我在第一个查询中做错了什么导致包含不起作用?

顺便说一句,另一个帖子也有同样的问题,他必须使用Customize. 我想正确地做到这一点。

4

1 回答 1

1

我不知道为什么负载不适合你,你在哪个版本的 raven 上?我刚刚在 Raven 2.5 build 2700 中对此进行了测试,并且包含在一个请求中为我带回了信息。

无论如何,由于负载不像我预期的那样工作,我会切换到一组惰性查询,以在 2 次服务器往返中获得你想要的东西。http://ravendb.net/docs/2.5/client-api/querying/lazy-operations

另一个可能对您更有效的选择(取决于您对所有这些数据的实际操作)是转换器。http://ravendb.net/docs/2.5/client-api/querying/results-transformation/result-transformers?version=2.5

希望有帮助。

于 2013-11-25T05:35:26.387 回答