I am having trouble with a LINQ query with Realm Xamarin (C#).
When creating the following classes, and try to fetch all DogModel objects where Person is null, I get a "Date type mismatch" RealmException:
public class DogModel : RealmObject
{
[PrimaryKey]
public long Id { get; set; }
public PersonModel Owner { get; set; }
}
public class PersonModel : RealmObject
{
[PrimaryKey]
public long Id { get; set; }
}
var p1 = new PersonModel();
p1.Id = 1;
var d1 = new DogModel();
d1.Id = 1;
d1.Owner = p1;
var d2 = new DogModel();
d2.Id = 2;
d2.Owner = null;
var _realm = Realm.GetInstance();
_realm.Write(() =>
{
_realm.Add(p1, true);
_realm.Add(d1, true);
_realm.Add(d2, true);
});
var data1 = Realm.GetInstance().All<DogModel>()
.ToList(); // This works
var data2 = Realm.GetInstance().All<DogModel>()
.Where(x => x.Owner == null)
.ToList(); // This does not work
In the second LINQ query I would expect to get a list with 1 item (DogModel with Id 2), but instead a "Date type mismatch" RealmException is thrown.
Why does this happen? Is there a way to do it?
Update 11/14/17 : A fix for this has been released with Realm .NET 2.1.0 .
This is indeed a bug in the Realm Xamarin SDK. I've opened an issue to track it: https://github.com/realm/realm-dotnet/issues/1596 . There's no workaround at the moment, but you're right - when it's fixed, it should just work without adding extra properties.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.