Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/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# sqlite net extensions InsertOrReplaceWithChildren不插入子外键字段_C#_Sqlite_Xamarin_Sqlite Net - Fatal编程技术网

C# sqlite net extensions InsertOrReplaceWithChildren不插入子外键字段

C# sqlite net extensions InsertOrReplaceWithChildren不插入子外键字段,c#,sqlite,xamarin,sqlite-net,C#,Sqlite,Xamarin,Sqlite Net,我有以下课程: class A { [PrimaryKey] public int A_ID { get; set; } [OneToMany(CascadeOperations=CascadeOperation.All)] public List<B> Children { get; set; } } class B { [PrimaryKey] public int B_ID { get; set; } [Foreig

我有以下课程:

class A
{
    [PrimaryKey]
    public int A_ID { get; set; }

    [OneToMany(CascadeOperations=CascadeOperation.All)]
    public List<B> Children { get; set; }
}

class B
{
    [PrimaryKey]
    public int B_ID { get; set; }

    [ForeignKey(typeof(C))]
    public int C_ID { get; set; }
}

class C
{
    [PrimaryKey]
    public int C_ID { get; set; }
}
当我选择记录B时:

B bDatabaseRecord = db.Get<B>(bRecord => bRecord.B_ID == bInstance.B_ID).First();
//bDatabaseRecord.C_ID is 0      <-- the problem
bbdatabaserecord=db.Get(bRecord=>bRecord.B_ID==bin实例.B_ID).First();

//bDatabaseRecord.C_ID为0我遇到了这个问题,通过在类B中标识类C的对象(作为外键对象)并将关系标记为ReadOnly=true解决了这个问题。 所以代码应该是

class A
{
    [PrimaryKey]
    public int A_ID { get; set; }

    [OneToMany(CascadeOperations=CascadeOperation.All)]
    public List<B> Children { get; set; }
}

class B
{
    [PrimaryKey]
    public int B_ID { get; set; }

    [OneToOne(ReadOnly=true)]
    public C C_Obj { get; set; }

    [ForeignKey(typeof(C))]
    public int C_ID { get; set; }
}

class C
{
    [PrimaryKey]
    public int C_ID { get; set; }
} 
A类
{
[主密钥]
公共int A_ID{get;set;}
[OneToMany(级联操作=级联操作.All)]
公共列表子项{get;set;}
}
B类
{
[主密钥]
公共int B_ID{get;set;}
[OneTONE(只读=真)]
公共C_Obj{get;set;}
[外键(类型(C))]
公共int C_ID{get;set;}
}
C类
{
[主密钥]
公共int C_ID{get;set;}
} 
我希望此解决方案适合您:)

class A
{
    [PrimaryKey]
    public int A_ID { get; set; }

    [OneToMany(CascadeOperations=CascadeOperation.All)]
    public List<B> Children { get; set; }
}

class B
{
    [PrimaryKey]
    public int B_ID { get; set; }

    [OneToOne(ReadOnly=true)]
    public C C_Obj { get; set; }

    [ForeignKey(typeof(C))]
    public int C_ID { get; set; }
}

class C
{
    [PrimaryKey]
    public int C_ID { get; set; }
}