Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 领域Xamarin.Forms可以';找不到现有项目_C#_Xamarin_Xamarin.forms_Realm_Realm Mobile Platform - Fatal编程技术网

C# 领域Xamarin.Forms可以';找不到现有项目

C# 领域Xamarin.Forms可以';找不到现有项目,c#,xamarin,xamarin.forms,realm,realm-mobile-platform,C#,Xamarin,Xamarin.forms,Realm,Realm Mobile Platform,我正致力于在Xamarin.Forms Android和iOS应用程序上实现领域平台和同步领域。使用下面的代码,我可以创建/连接到应该存储数据的realm实例,并且可以向该实例添加新对象。然而,无论我做什么,我都得不到 realm.Find(“ID-1”) 归还任何东西。在try()catch()中,该行返回:“对象引用未设置为对象的实例”。使用RealmStudio,我可以看到正在进行的更改,并且我可以看到我在应用程序上查找的对象存在 此外,如果我尝试查询元素,无论指定哪个参数,我总是得到0

我正致力于在Xamarin.Forms Android和iOS应用程序上实现领域平台和同步领域。使用下面的代码,我可以创建/连接到应该存储数据的realm实例,并且可以向该实例添加新对象。然而,无论我做什么,我都得不到

realm.Find(“ID-1”)

归还任何东西。在
try()catch()
中,该行返回:“对象引用未设置为对象的实例”。使用RealmStudio,我可以看到正在进行的更改,并且我可以看到我在应用程序上查找的对象存在

此外,如果我尝试查询元素,无论指定哪个参数,我总是得到0

型号:

public class Person : RealmObject
{
    [PrimaryKey]
    public string Id { get; set; }

    public int Number {get; set;}

    public string DeviceName { get; set; }
    public string DeviceId { get; set; }

    public IList<SoundSnapModel> SnapList { get;}

    public Person()
    {

    }
}
 var credentials = Credentials.Nickname("Thanos", false);
 var InstanceId = "instance-name";
 var serverURL = new Uri("realms://" + InstanceId + "/~/testRealm3");
 var AUTH_URL = new Uri("https://" + InstanceId + "/auth");
 var user = await User.LoginAsync(credentials, AUTH_URL);

 var configuration = new QueryBasedSyncConfiguration(serverURL, user);
 var realm = Realm.GetInstance(configuration);

 realm.Write(() => realm.Add(new Person { Id = "ID-1", Number = 123,     
 DeviceId = "something", DeviceName = "something" }));  // works without issue
 Debug.WriteLine("Added new person!!");

 var elements = realm.All<Person>().Where(e => e.Number > 100);
 Debug.WriteLine("Found the object list: " + elements.Count() + "  "); // returns 0

 var currentObject = realm.Find<Person>("ID-1"); // triggers the exception mentioned above
公共类人物:RealmObject
{
[主密钥]
公共字符串Id{get;set;}
公共整数{get;set;}
公共字符串DeviceName{get;set;}
公共字符串设备ID{get;set;}
公共IList快照列表{get;}
公众人士()
{
}
}
代码片段:

public class Person : RealmObject
{
    [PrimaryKey]
    public string Id { get; set; }

    public int Number {get; set;}

    public string DeviceName { get; set; }
    public string DeviceId { get; set; }

    public IList<SoundSnapModel> SnapList { get;}

    public Person()
    {

    }
}
 var credentials = Credentials.Nickname("Thanos", false);
 var InstanceId = "instance-name";
 var serverURL = new Uri("realms://" + InstanceId + "/~/testRealm3");
 var AUTH_URL = new Uri("https://" + InstanceId + "/auth");
 var user = await User.LoginAsync(credentials, AUTH_URL);

 var configuration = new QueryBasedSyncConfiguration(serverURL, user);
 var realm = Realm.GetInstance(configuration);

 realm.Write(() => realm.Add(new Person { Id = "ID-1", Number = 123,     
 DeviceId = "something", DeviceName = "something" }));  // works without issue
 Debug.WriteLine("Added new person!!");

 var elements = realm.All<Person>().Where(e => e.Number > 100);
 Debug.WriteLine("Found the object list: " + elements.Count() + "  "); // returns 0

 var currentObject = realm.Find<Person>("ID-1"); // triggers the exception mentioned above
var-credentials=credentials.昵称(“Thanos”,false);
var InstanceId=“实例名称”;
var serverURL=newuri(“realms://“+InstanceId+”/~/testRealm3”);
var AUTH_URL=新Uri(“https://“+InstanceId+”/AUTH”);
var user=wait user.LoginAsync(凭证、身份验证URL);
var配置=新的QueryBasedSyncConfiguration(服务器URL,用户);
var realm=realm.GetInstance(配置);
realm.Write(()=>realm.Add)(newperson{Id=“Id-1”,Number=123,
DeviceId=“something”,DeviceName=“something”}));//工作没有问题
Debug.WriteLine(“添加了新的人员!!”);
var elements=realm.All(),其中(e=>e.Number>100);
Debug.WriteLine(“找到对象列表:“+elements.Count()+”);//返回0
var currentObject=realm.Find(“ID-1”);//触发上述异常

QueryBasedSyncConfiguration
是在我离开Realm Xamarin团队后添加的,但我认为它不起作用,因为您没有完全配置它

查看订阅,很明显您必须设置订阅

默认情况下,基于查询的同步领域不包含任何数据。相反,客户端应用程序必须选择或订阅服务器上相应领域中要同步的数据子集

您没有创建他们描述的订阅:

var subscription=realm.All().Where(e=>e.Number>100.subscripte()

我相当肯定,即使您在本地创建数据,但在您拥有包含数据的订阅之前,数据实际上并不存在于本地