我想獲得所有元素的修改屬性沒有設置,但似乎無法讓它與Realm一起使用。如何使用Realm中的Linq表達式檢查Nullable類型的null?
示例代碼:
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實際支持的內容?
使用領域Xamarin v0.77.1在Android
編輯:
我曾嘗試creating a linq expression tree被評論者的建議。這導致了System.MissingMethodException: Method 'RealmResults'1.get_Provider' not found.
例外。
謝謝你的建議。嘗試一下後,我無法讓它工作。我收到以下異常:'System.MissingMethodException:Method'RealmResults'1.get_Provider'not found.'。所以它編譯好,但在運行時拋出一個錯誤。 – Marc