我在RavenDb中存储了许多命令,它们都实现了ICommand.我希望能够搜索上次修改的和Raven-Entity-Name的元数据.我目前正在对每个命令执行多个映射,如下所示:
public class CommandAuditSearch_Index : AbstractMultiMapIndexCreationTask<CommandAuditSearch_Index.Results>
{
public class Results
{
public string CommandType { get; set; }
public DateTime LastModified { get; set; }
}
public CommandAuditSearch_Index()
{
AddMap<NewEmployeeStartCommand>(employees => employees.Select(x => new
{
CommandType = MetadataFor(x).Value<string>("Raven-Entity-Name"),
LastModified = MetadataFor(x).Value<DateTime>("Last-Modified")
}));
AddMap<EmployeeLeaverCommand>(employees => employees.Select(x => new
{
CommandType = MetadataFor(x).Value<string>("Raven-Entity-Name"),
LastModified = MetadataFor(x).Value<DateTime>("Last-Modified")
}));
Index(results => results.CommandType, FieldIndexing.Analyzed);
}
}
Run Code Online (Sandbox Code Playgroud)
我查询如下:
session.Query<CommandAuditSearch_Index.Results, CommandAuditSearch_Index>()
.Where(x => x.CommandType == commandType && x.LastModified >= DateTime.Today).OfType<ICommand>().ToList();
Run Code Online (Sandbox Code Playgroud)
我知道Raven中已经内置了一个索引来获取Tag(实体名称)和最后修改日期,但我似乎无法弄清楚如何得到结果,因为上面的索引给了我.
任何人都可以指向我在静态索引的正确方向,我不必为我必须查询的每个命令都有如上所述的多个映射,这样可以将结果作为ICommands列表?
谢谢
稻田
ravendb ×1