WriteOperations.InsertWithChildren cannot set recursive flag

Issue #59 resolved
Nhat Anh created an issue

Hello,

I've created 3 tables: class Book { [PrimaryKey, AutoIncrement] public int RowID { get; set; }

    public string Title { get; set; }

    public string Sub { get; set; }

    [ManyToMany(typeof(BookAuthor),"BTitle", "authorL",CascadeOperations =  CascadeOperation.All)]
    public List<author> BookL { get; set;}

}

class author
{

    [PrimaryKey, AutoIncrement]
    public int RowID { get; set; }

    public string Name { get; set; }

    public string Mail { get; set; }

    [ManyToMany(typeof(BookAuthor), "Bauthor", "BookL", CascadeOperations = CascadeOperation.All)]
    public List<Book> authorL { get; set; }
}

class BookAuthor
{
    [PrimaryKey, AutoIncrement]
    public int RowID { get; set; }

   [ForeignKey(typeof(Book))]
    public string BTitle { get; set; }

    [ForeignKey(typeof(author))]
    public string Bauthor { get; set; }
}

And I'm trying to Insert into the author table through the Book table, via the connections between them; I didn't try one-to-one because the request of the project is the two tables of "author" and "Book" have to link through another table in the middle "BookAuthor".

 public void insertFK()
    {
        SQLiteConnection db = new SQLiteConnection(DBP);

        var Book1 = new Book
        {
            Title = "First Book",
            Sub = "First Sub"
        };

        var author1 = new author
        {
            Name = "First author",
            Mail = "first mail"
        };



        Book1.BookL = new List<author> { author1 };

        bool xx= true;

        WriteOperations.InsertWithChildren(db, Book1, recursive: true  );

    }

But - I can't find the function bd.InsertWithChildren(), so after searching in Object Browser I found it in the WriteOpreations.

  • I can't set the recursive flag. If I type it like the above, it saids "the best overload methods for .......has some invalid arguments"

I don't understand, please help!! Yep I'm totally new in this area :<

Comments (4)

  1. Guillermo Gutiérrez

    SQLite-Net Extensions declares its methods as extensions of SQLiteConnection, so you have to change the last line to:

    db.InsertWithChildren(Book1, recursive: true);
    

    You can browse the IntegrationTests project for a lot of samples.

  2. Guillermo Gutiérrez

    Sounds like you're using a different SQLite-Net version of the one expected by SQLite-Net Extensions. How did you include the libraries in your project?

  3. Guillermo Gutiérrez

    Yes, you should use SQLite.Net PCL or copy the SQLite-Net Extension sources to your project (this one is probably easier for WP 8.1 projects).

  4. Log in to comment