Irwsoft Data Framework

Insert Multi Values into Multi Tables in Oracle
Brief Information
DataschemaTable and View.
TopicsInsert Multi-tables syntax.

Oracle provider supports insert syntax to insert multi values/records into multi tables. This feature a little bit different with the common insert multi values of SqlCLient and MySql providers, which is it insert into single table only.

This sample will show how to insert multi values into Person and Country tables in Oracle database.

C# code
// declare new instance but do not need to set its values,
// because you will set the values in different way you insert into single table.

PersonTable person = new PersonTable();

// using OracleInsertIntoMultiTables to insert values into multi tables
// pass the person as the first table to insert.

OracleInsertIntoMultiTables insert = new OracleInsertIntoMultiTables(person);
// Don’t forget to set connection string !
// NOTE : it is optional if the data-schema class using default connection .

insert.ConnectionString = "...";  // [OPTIONAL]

// NOTE : because it is multi-tables insertion, you must define each table one by one.
// 1) Specify the columns of the first table (zero index based) to insert and fill with the array of values.

insert[0].Column(person.PersonId, person.FirstName, person.LeaderId).Value(1000, "NewPerson-1", null);

// 2) You can add another record with same dataschema class like below.
insert.Into(person).Column(person.PersonId, person.FirstName, person.LeaderId).Value(1001, "NewPerson-2", 1000);

// 3) You can also add another record with other dataschema class like below.
// declare new instance of Country but do not need to set its values

CountryTable country = new CountryTable();

// 4) Specify the columns of the Country table to insert and fill with the array of values.
insert.Into(country).Column(country.CountryId, country.CountryName).Value(1000, "NewCountry-1");

// Execute the query and return number of rows affected by operation.
int r = insert.Execute();

How to insert multi tables in Oracle using Irwsoft Data Framework

Related Topics :

Irwsoft Data Ultimate Edition provides all enhanced features of Irwsoft Data Framework and support from irwsoft.