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
如何使用Sqlite扩展创建OneToOne关系_Sqlite_Xamarin_Mvvmcross_Sqlite Net Extensions - Fatal编程技术网

如何使用Sqlite扩展创建OneToOne关系

如何使用Sqlite扩展创建OneToOne关系,sqlite,xamarin,mvvmcross,sqlite-net-extensions,Sqlite,Xamarin,Mvvmcross,Sqlite Net Extensions,基本上我有一个Client类和一个Address类,如下所示 public class Client { [PrimaryKey, AutoIncrement] public int Id { get; set; } public string Description{ get; set; } public string Email { get; set; } public string Website { get; set; } public s

基本上我有一个
Client
类和一个
Address
类,如下所示

public class Client
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    public string Description{ get; set; }
    public string Email { get; set; }
    public string Website { get; set; }
    public string PhoneNumber { get; set; }

    [ForeignKey(typeof(Address))]
    public int AddressId { get; set;}
    [OneToOne(CascadeOperations = CascadeOperation.All)]
    public Address Address { get; set; }
}

public class Address
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    public string Line1 {get;set;}
    public string Line2 {get;set;}
    public string Line3 {get;set;}
    public string Line4 {get;set;}
    public string Line5 {get;set;}
    public string Line6 {get;set;}
}
我正在使用nuget包SQLite.Net-PCL和SQLite.Net-PCL扩展,这样我基本上可以调用Insert并传递
Client
对象来保存一个客户机,并将其完整的地址保存到数据库中。像这样:

_db.InsertWithChildren(clientObject);
在我的应用程序(带有MvvmCross的Xamarin.iOS)中,我已将一个预先存在的数据库与应用程序捆绑在一起,因此我不会在代码中创建表,因此我的失败点在
InsertWithChildren(clientObject)
调用上

我已经尝试删除先前存在的表,然后在代码中创建表,
Address
table,然后
Client
,但是在创建客户端表时,它告诉我它“不知道”有关
Address
类型/属性的信息。如果您先尝试
客户端
表,则会出现相同的错误。我尝试了尽可能多的方法,只需在一次呼叫中保存客户机的地址,但没有效果


有人能解释一下吗?

这个问题是因为所有关系属性都继承自SQLite Net
Ignore
attribute。如果您使用不同的SQLite Net版本,它将无法识别
Ignore
属性,并且它将尝试保留带注释的属性,导致它因您看到的错误而崩溃

长话短说:您可能正在使用一个SQLite网络扩展的注释和另一个SQLite网络版本的数据库连接


如果您使用的是SQLite Net MvvmCross社区版,则必须使用,而不是PCL社区版。

当我安装MvvmCross 2时,如果我没记错的话,SQLite Connection类出现了问题。我不知道如何解决它,所以我回到了问题中提到的PCL 2。太好了,谢谢!毫无疑问,这似乎是我正在经历的问题。我以前甚至尝试过明确忽略这些属性,但也不起作用。你能把这个解释作为一个回应,让其他人从中受益吗?我想问的最后一件事是,我如何确保Sqlite.Net和SqliteNet扩展都是“匹配对”——因为我知道如果你得到了错误的配对,它们将无法工作,但仍然会被它绊倒。如果这对你来说不是太麻烦的话,你能告诉我哪个包与哪个包在nuget包的URL方面是一致的吗。我想得到这个软件包的扩展。但在这一阶段,我会接受任何一对工作人员,并处理其后果。