我对 RavenDB 很陌生,正在努力寻找以下解决方案:
我有一个名为 ServiceCalls 的集合,如下所示:
public class ServiceCall
{
public int ID { get; set; }
public string IncidentNumber { get; set; }
public string Category { get; set; }
public string SubCategory { get; set; }
public DateTime ReportedDateTime { get; set; }
public string Block { get; set; }
public decimal Latitude { get; set; }
public decimal Longitude { get; set; }
}
我有一个名为 ServiceCalls/CallsByCategory 的索引,如下所示:
Map = docs => from doc in docs
select new
{
Category = doc.Category,
CategoryCount = 1,
ServiceCalls = doc,
};
Reduce = results => from result in results
group result by result.Category into g
select new
{
Category = g.Key,
CategoryCount = g.Count(),
ServiceCalls = g.Select(i => i.ServiceCalls)
};
所以输出是:
public class ServiceCallsByCategory
{
public string Category { get; set; }
public int CategoryCount { get; set; }
public IEnumerable<ServiceCall> ServiceCalls { get; set; }
}
使用此查询一切正常
var q = from i in session.Query<ServiceCallsByCategory>("ServiceCalls/CallsByCategory") select i
我完全迷失的地方是编写一个允许我按 ReportedDateTime 查询的索引。可以让我这样做的东西:
var q = from i in session.Query<ServiceCallsByCategory>("ServiceCalls/CallsByCategory")
where i.ServiceCalls.Any(x=>x.ReportedDateTime >= new DateTime(2012,10,1))
select i
任何指导将不胜感激。