【发布时间】:2016-08-04 09:43:59
【问题描述】:
我想获取未设置 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
编辑:
我确实按照评论者的建议尝试了creating a linq expression tree。这导致了 System.MissingMethodException: Method 'RealmResults'1.get_Provider' not found. 异常。
【问题讨论】:
-
感谢您的建议。试一试后,我无法让它工作。我收到以下异常:
System.MissingMethodException: Method 'RealmResults'1.get_Provider' not found.。所以它编译得很好,但在运行时会抛出一个错误。
标签: c# linq xamarin realm realm-net