gpt4 book ai didi

c# - 乌鸦数据库 : What's wrong with this multimap/reduce index?

转载 作者:太空宇宙 更新时间:2023-11-03 11:16:32 24 4
gpt4 key购买 nike

我对上次使用和使用计数的 Sum 和 Max 调用是错误的。它们始终是存储在当前设置为 0 的第二个映射值中的值。我可以将其设置为 -100,这就是 reduce 结果。我注意到有人说你应该把它做成一个数组,但我不明白这有什么帮助。我有一个使用 map/reduce 的对象的 linq 表达式,假设两个映射联合在一起,它可以正常工作。

这是数据=> https://gist.github.com/940ccca1b0f8917e9eaf

我想支持这样的查询

        var stats = Session.Query<MultiMapApiKeyStats.ApiKeyStats, MultiMapApiKeyStats>()
.Customize(x => x.WaitForNonStaleResultsAsOfNow())
.Where(x => x.AccountId == Account.Id)
.OrderBy(x => x.Key).ToList();

然后建一个表 table

 public MultiMapApiKeyStats()
{
AddMap<KeyUsageBase>(uses => from use in uses
select new
{
AccountId = use.AccountId,
ApiKeyId = use.ApiKeyId,
Key = (string)null,
UsageCount = 1,
LastUsed = use.LastUsedTicks,
Pattern = (string)null,
Status = ApiKey.KeyStatus.None,
Type = ApiKey.ApplicationType.None
});
AddMap<ApiKey>(keys => from key in keys
select new
{
AccountId = key.AccountId,
ApiKeyId = key.Id,
Key = key.Key,
UsageCount = 0,
LastUsed = 0,
Pattern = key.Pattern,
Status = key.ApiKeyStatus,
Type = key.Type
});


Reduce = results => from result in results
group result by result.ApiKeyId
into g
select new
{
AccountId = g.Select(x => x.AccountId).FirstOrDefault(),
ApiKeyId = g.Key,
Key = g.Select(x => x.Key).FirstOrDefault(x => x != null),
UsageCount = g.Sum(x => x.UsageCount),
LastUsed = g.Max(x => x.LastUsed),
Pattern = g.Select(x => x.Pattern).FirstOrDefault(),
Status = g.Select(x => x.Status).FirstOrDefault(),
Type = g.Select(x => x.Type).FirstOrDefault()
};

最佳答案

索引错误 sequence contains no matching elements 是在空集合上调用 First 的结果,这就是您应该使用 FirstOrDefault 的原因。此外,在 map 和 reduce 声明中引用您自己的类会导致错误,因为 RavenDB 无法在索引时解析这些类型。

关于c# - 乌鸦数据库 : What's wrong with this multimap/reduce index?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12505097/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com