0
我正在嘗試在Raven查詢中完成一個子集合計數的總和。它返回的計數爲0.如果我直接在對象上使用相同的LINQ,則它的計數爲2.RavenDB計數總和
這個查詢是否可以在Raven上自動索引?如果我需要創建一個map-reduce索引,有人可以幫助我嗎?
[TestMethod]
public void CalculateUserClickCount()
{
var db = new EmbeddableDocumentStore { RunInMemory = true };
db.Initialize();
using (var session = db.OpenSession())
{
var user = new User();
var product = new Product();
product.Clicks.Add(new Click());
product.Clicks.Add(new Click());
user.Storefront.EndoProducts.Add(product);
session.Store(user);
session.SaveChanges();
var users = session.Query<User>()
.Customize(t => t.WaitForNonStaleResults())
.Select(t => new
{
StoreFrontId = t.Storefront.StorefrontID,
itemCount = t.Storefront.EndoProducts.Count,
updateDate = t.Storefront.LastUpdateDate,
clickCount = t.Storefront.EndoProducts.Sum(r => r.Clicks.Count), // this is improperly set to 0
TotalAffiliateRevenue = t.Storefront.SaleReports.Sum(r => r.TotalAffiliateEarnings) // this works
})
.ToList();
int clickCount = user.Storefront.EndoProducts.Sum(t => t.Clicks.Count); // this is properly set to 2
Assert.AreEqual(2, users[0].clickCount);
}
}