【发布时间】:2018-07-03 19:01:55
【问题描述】:
我有两个模型 Parent 和 Child(一对多),Parent 包含 IList Children。
在我的视图模型中,我有一个绑定到属性 ChildList 的 ListView。
ChildList = _dataService.Realm.All<Parent>().First(d => d.ParentId == "MyParentIdentifier").Children;
将产生实时查询(如果我向 IList 添加或删除 Child,它将反映在 UI 中)。
ChildList = _dataService.Realm.All<Parent>().First(d => d.ParentId == "MyParentIdentifier").Children.Where(d => d.ChildName.StartsWith("A"));
不会产生实时查询。 UI 只会在关闭并重新打开页面后更新。
如何通过此设置创建实时查询?我还尝试向 Child 模型添加反向链接属性和如下查询:
ChildList = _dataService.Realm.All<Child>().Where(d => d.Parent.ParentId == "MyParentIdentifier");
但这会导致崩溃并出现错误:
System.NotSupportedException:Equal 运算符的左侧 必须是对 Realm 中持久属性的直接访问。无法 处理“d.Parent.ParentId”。
【问题讨论】:
-
应根据github.com/realm/realm-dotnet/issues/219支持跨反向链接查询
标签: c# .net xamarin.forms realm