RavenDB-获取非根级别属性中根属性的ID

RavenDB-获取非根级别属性中根属性的ID,ravendb,Ravendb,使用RavenDB,是否可以在另一个属性中获取属性的ID?例如,如果Foo有一个Bar对象列表,并且每个Bar对象都有一个SnuhId属性,那么我可以使用一个Include来获取每个Snuh属性的id吗 我尝试了下面的查询,但得到了RavenDB异常:索引超出范围。在这个查询中,ApplicationServer是一个根元素,它有一个ApplicationWithOverrideGroup对象的列表。每个对象都有一个ApplicationId属性。这是我想要包含的应用程序ID IEnumerab

使用RavenDB,是否可以在另一个属性中获取属性的ID?例如,如果Foo有一个Bar对象列表,并且每个Bar对象都有一个SnuhId属性,那么我可以使用一个Include来获取每个Snuh属性的id吗

我尝试了下面的查询,但得到了RavenDB异常:索引超出范围。在这个查询中,ApplicationServer是一个根元素,它有一个ApplicationWithOverrideGroup对象的列表。每个对象都有一个ApplicationId属性。这是我想要包含的应用程序ID

IEnumerable<ApplicationServer> appServers = QueryAndCacheEtags(session =>
  session.Advanced.LuceneQuery<ApplicationServer>()
  .Include(x => x.CustomVariableGroupIds)
  // This is the line I'm trying to make work:
  .Include(x => (from item in x.ApplicationsWithOverrideGroup select item.ApplicationId).ToList())
  ).Cast<ApplicationServer>();

如果第一个选项确实有效,那么在Include()中指定的属性将包括其中的ID属性。是这样吗

我不确定这两种方法是否都有效,但它们似乎都有效。如果两者都有效,我想知道其中一个是否比另一个好


好吧,那不行。请求的数量在增加,我猜这意味着访问DB的次数在增加,而不仅仅是会话中的内容。

好的,以上问题中的建议都不起作用。我认为必须做的是在根对象中包含嵌套属性的ID

这就是我所做的,我能够将会话对象上的请求数降到1。奇怪的是,我不得不改变这一点:

// Not using this, at least for now, because it increased the NumberOfRequests on the session...
appServer.CustomVariableGroups = new ObservableCollection<CustomVariableGroup>(
QueryAndCacheEtags(session => session.Load<CustomVariableGroup>(appServer.CustomVariableGroupIds)).Cast<CustomVariableGroup>());
//至少目前不使用它,因为它增加了会话上的请求数。。。
appServer.CustomVariableGroups=新的ObservableCollection(
QueryAndCacheTags(session=>session.Load(appServer.CustomVariableGroupId)).Cast();
为此:

// ... however, this kept the NumberOfRequests to just one. Not sure why the difference.
appServer.CustomVariableGroups = new ObservableCollection<CustomVariableGroup>();
foreach (string groupId in appServer.CustomVariableGroupIds)
{                
  appServer.CustomVariableGroups.Add(QuerySingleResultAndCacheEtag(session => session.Load<CustomVariableGroup>(groupId)) as CustomVariableGroup);
}
/。。。然而,这使得请求的数量仅为一个。不知道为什么会有不同。
appServer.CustomVariableGroups=新的ObservableCollection();
foreach(appServer.CustomVariableGroupId中的字符串groupId)
{                
添加(QuerySingleResultAndCacheEtag(session=>session.Load(groupId))作为CustomVariableGroup);
}

我不知道你想做什么,但如果你说它行得通,那就顺其自然吧。:)一方面,没有理由对每个查询都调用.Cast()。我也不总是明白我在做什么。:)实际上我必须调用Cast(),因为我是在QueryAndCacheTags()上调用它,而不是在会话上调用它。QueryAndCacheTags()返回EntityBase,而不是ApplicationServer子类。
// Not using this, at least for now, because it increased the NumberOfRequests on the session...
appServer.CustomVariableGroups = new ObservableCollection<CustomVariableGroup>(
QueryAndCacheEtags(session => session.Load<CustomVariableGroup>(appServer.CustomVariableGroupIds)).Cast<CustomVariableGroup>());
// ... however, this kept the NumberOfRequests to just one. Not sure why the difference.
appServer.CustomVariableGroups = new ObservableCollection<CustomVariableGroup>();
foreach (string groupId in appServer.CustomVariableGroupIds)
{                
  appServer.CustomVariableGroups.Add(QuerySingleResultAndCacheEtag(session => session.Load<CustomVariableGroup>(groupId)) as CustomVariableGroup);
}