Setting CascadeOperations.CascadeInsert on a OneToOne relationship throws an exception

Issue #8 invalid
Matt Benic created an issue

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)

  1. Guillermo Gutiérrez

    Thanks for the report. Test case already created and reproduced the issue. Working on the fix.

  2. Guillermo Gutiérrez

    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.

  3. Guillermo Gutiérrez

    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; }
    }
    
  4. Log in to comment