Setting CascadeOperations.CascadeInsert on a OneToOne relationship throws an exception
Issue #8
invalid
Using the following classes:
[Table("RecursiveParent")]
public class RecursiveParent
{
[PrimaryKey, AutoIncrement]
public int Id { get; set;}
[ForeignKey(typeof(RecursiveChildSingle))]
public int SingleId { get; set;}
[OneToOne(CascadeOperations = CascadeOperation.CascadeInsert)]
public RecursiveChildSingle Single { get; set;}
[OneToMany(CascadeOperations = CascadeOperation.All)]
public RecursiveChildMultiple[] Multiple { get; set;}
}
[Table("RecursiveChildSingle")]
public class RecursiveChildSingle
{
[PrimaryKey, AutoIncrement]
public int Id { get; set;}
}
[Table("RecursiveChildMultiple")]
public class RecursiveChildMultiple
{
[PrimaryKey, AutoIncrement]
public int Id { get; set;}
[ForeignKey(typeof(RecursiveParent))]
public int ParentId {get;set;}
}
And then creating and inserting an object as follows throws an exception (note that inserting with recursive:false does not):
Connection.CreateTable<RecursiveChildMultiple>();
Connection.CreateTable<RecursiveChildSingle>();
Connection.CreateTable<RecursiveParent>();
var parent = new RecursiveParent
{
Single = new RecursiveChildSingle(),
Multiple = new []
{
new RecursiveChildMultiple(),
new RecursiveChildMultiple()
}
};
Connection.InsertWithChildren(parent, recursive: true);
Comments (4)
-
-
The exception is raised when you call
Connection.Update
on an object that doesn't contain any other field other than the primary key. I don' think that I can solve it from the library. -
Adding any other field to
RecursiveChildSingle
makes it work. Definitely not a SQLite-Net Extensions bug.[Table("RecursiveChildSingle")] public class RecursiveChildSingle { [PrimaryKey, AutoIncrement] public int Id { get; set;} public string Name { get; set; } }
-
- changed status to invalid
- Log in to comment
Thanks for the report. Test case already created and reproduced the issue. Working on the fix.