RavenDB Multimap 索引 - 文档不在两个集合中

RavenDB Multimap index - documents not in both collections

我知道如何在 SQL 世界中做到这一点,但试图在 RavenDB 领域解决这个问题。

我有 2 个 类 这样的:

public class Client
{
  public string Id {get;set;}
  public string Name {get;set;}
}

public class WaitingListEntry
{
  public string Id {get;set;}
  public string ClientId {get;set;}
  public string OtherDocumentInformation {get;set;}
}

而且相当直接 map/reduce:

AddMap<Client>(clients => from c in clients select new { Id = (string)null, ClientId = c.ClientId, Name = c.Name });

AddMap<WaitingListEntry>(wls => from wl in wls select new { Id = wl.Id, ClientId = wl.ClientId, Name = (string)null });

Reduce = results => from result in results
  group result by result.ClientId
  into g
  select new { Id = g.Select(x => x.Id).Where(x => x != null).First(),
    ClientId = g.Key,
    Name = g.Select(x => x.Name).Where(x => x != null).First()
  };

我 运行 遇到的问题是并非所有客户都在等候名单中,我想从索引中排除这些客户。我已经习惯了 SQL 思考,无法弄清楚在这里要做什么才能实现这一目标。

您不需要创建 multimap index。使用下面的 Index,您可以获取与客户的所有等候名单:

你会得到结果:

我用过这个数据:

session.Store(new Client() { Id = "client/1", Name = "Client 1" });
session.Store(new Client() { Id = "client/2", Name = "Client 2" });
session.Store(new Client() { Id = "client/3", Name = "Client 3" });

session.Store(new WaitingListEntry() { Id = "waitingListEntry/1", ClientId = "client/1", OtherDocumentInformation = "Info" });
session.Store(new WaitingListEntry() { Id = "waitingListEntry/2", ClientId = "client/2", OtherDocumentInformation = "Info" });

session.SaveChanges();