简体   繁体   English

LINQ查询中的“日期类型不匹配” RealmException

[英]“Date type mismatch” RealmException in LINQ query

I am having trouble with a LINQ query with Realm Xamarin (C#). 我在使用Realm Xamarin(C#)进行LINQ查询时遇到问题。

When creating the following classes, and try to fetch all DogModel objects where Person is null, I get a "Date type mismatch" RealmException: 创建以下类时,尝试获取Person为null的所有DogModel对象时,出现“日期类型不匹配” 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. 在第二个LINQ查询中,我希望获得包含1个项目的列表(ID为2的DogModel),但是会抛出“日期类型不匹配” RealmException。

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 . 更新11/14/17Realm .NET 2.1.0已发布了针对此问题的修复程序。

This is indeed a bug in the Realm Xamarin SDK. 这确实是Realm Xamarin SDK中的错误。 I've opened an issue to track it: https://github.com/realm/realm-dotnet/issues/1596 . 我打开了一个跟踪它的问题: 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. 目前尚无解决方法,但是您是对的-固定后,它应该可以正常工作而无需添加其他属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM