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
. 我想正确地做到这一点。