【发布时间】:2023-03-06 15:28:02
【问题描述】:
我有 2 个表:Quest 和 HistoryItem;
简化任务:
public class Quest : RealmObject
{
[PrimaryKey]
public string Id { get; set; } = Guid.NewGuid().ToString();
public string Name { get; set; }
public int MaxRepeats { get; set; }
}
简化历史:
public class HistoryItem : RealmObject
{
[PrimaryKey]
public string Id { get; set; } = Guid.NewGuid().ToString();
public DateTimeOffset DoneTime { get; set; }
public Quest Quest { get; set; }
}
如何正确编写领域子查询以显示所有已完成少于 questItem.MaxRepeats 的任务?如果每个完成的任务都将添加到新的 HistoryItem.Quest 字段中;
据我了解,它一定是这样的:
_db.Realm.All<Quest>().Filter($"SUBQUERY(HistoryItem, $hi, $hi.Quest).@count > $hi.Quest.MaxRepeats");
但由于某种原因没有正确过滤=(
Realms.Exceptions.RealmException: 'SUBQUERY(HistoryItem, $hi, $hi.Quest).@count > $hi.Quest.MaxRepeats:1:8(8): 无效谓词。'
此子查询是基于documentation 示例编写的:
realm.All<Person>().Filter("SUBQUERY(Dogs, $dog, $dog.Vaccinated == false).@count > 3");
// find all people who have more than 3 unvaccinated dogs.
也许,这里会有一些有用的信息NSPredicateCheatsheet 或这里js filter usage samples
【问题讨论】: