static void InsertBulk()
{
string documentConnectionString = $"Data Model=Document;Uri='json_bookstore.json';Json Path='$.bookstore.books'";
using (C1JsonConnection con = new C1JsonConnection(documentConnectionString))
{
// Populate Datatable
C1JsonDataAdapter adapter = new C1JsonDataAdapter(con, "SELECT * FROM books");
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
// Create Insert command
adapter.InsertCommand = new C1JsonCommand(con);
adapter.InsertCommand.CommandText = "INSERT INTO books(_id, genre, publicationdate, ISBN, title, [author.first-name], [author.last-name], price) " +
"VALUES(@id, @genre, @publicationdate, @ISBN, @title, @fname, @lname, @price)";
// Add query parameters
adapter.InsertCommand.Parameters.Add("@id", "_id");
adapter.InsertCommand.Parameters.Add("@genre", "genre");
adapter.InsertCommand.Parameters.Add("@publicationdate", "publicationdate");
adapter.InsertCommand.Parameters.Add("@ISBN", "ISBN");
adapter.InsertCommand.Parameters.Add("@title", "title");
adapter.InsertCommand.Parameters.Add("@price", "price");
adapter.InsertCommand.Parameters.Add("@fname", "author.first-name");
adapter.InsertCommand.Parameters.Add("@lname", "author.last-name");
adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None;
// Insert one row
DataRow bookRow1 = dataTable.NewRow();
bookRow1["_id"] = "22";
bookRow1["genre"] = "novel";
bookRow1["publicationdate"] = "2021-11-17";
bookRow1["ISBN"] = "0-201-63361-2";
bookRow1["title"] = "Lorem Ipsum";
bookRow1["price"] = 11.99;
bookRow1["author.first-name"] = "fname test 1";
bookRow1["author.last-name"] = "lname Test 1";
dataTable.Rows.Add(bookRow1);
// Insert another row
DataRow bookRow2 = dataTable.NewRow();
bookRow2["_id"] = "23";
bookRow2["genre"] = "roman";
bookRow2["publicationdate"] = "2018-12-07";
bookRow2["ISBN"] = "0-885-76699-4";
bookRow2["title"] = "Dolores Ipsum";
bookRow2["price"] = 10.65;
bookRow2["author.first-name"] = "fname test 2";
bookRow2["author.last-name"] = "lname Test 2";
dataTable.Rows.Add(bookRow2);
// Update database
adapter.Update(dataTable);
Console.WriteLine("Bulk insert successful! \n\n");
}
}