我想获取未设置 Modified 属性但似乎无法使其与 Realm 一起使用的所有元素。
示例代码:
public class FooModel : RealmObject
{
public DateTimeOffset? Modified { get; set; }
}
...
public List<FooModel> GetAllUnmodified()
{
var realm = Realm.GetInstance();
//doesn't work
var result1 = realm.All<FooModel>().Where(model => model.Modified == null).ToList();
//doesn't work
var result2 = realm.All<FooModel>().Where(model => !model.Modified.HasValue).ToList();
//doesn't work
DateTimeOffset? testValue = null;
var result3 = realm.All<FooModel>().Where(model => model.Modified == testValue).ToList();
//doesn't work
var result4 = realm.All<FooModel>().Where(model => model.Modified == default(DateTimeOffset?)).ToList();
return result1;
}
总是得到System.NotSupportedException: The rhs of the binary operator 'Equal' should be a constant or closure variable expression.
或System.NotSupportedException: The member 'HasValue' is not supported
我错过了什么吗?有什么好方法可以查看 Realm 的 Linq 实际支持的内容吗?
在 Android 上使用 Realm Xamarin v0.77.1
编辑:
我确实尝试按照评论者的建议创建一个 linq 表达式树。这导致了System.MissingMethodException: Method 'RealmResults'1.get_Provider' not found.
异常。