Bulk Insert

Posts   
 
    
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 06-Jul-2010 15:30:26   

LLBLGEN 3.0 Frame work: LLBLGENRUNTIME DB: Oracle 9i

Hi, so far what ever issues i had, had been resolved either through documentation or by excellant support by your team.

Now am stuck with problem for which i could not find any help from documenation.

I am working on a tranction module and what I am trying to do i bulk insert.

I mean I have set of records which needs to be inserted in one table and commit only after all records are inserted. All examples shown are for single insert and I do not know how to insert bulk either through an array or by any other means. Please Help

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 06-Jul-2010 20:41:02   

http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/Adapter/gencode_usingcollectionclasses_adapter.htm

You can create a collection of entities of the correct type, and save the collection.. This will insert all of the entities.

Unless you are actually talking about bulk inserting many rows (1 million for example) using SQL servers bulk load functionality - LLBLGen does not have native support for this.

Matt

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 07-Jul-2010 06:00:57   

MTrinder wrote:

http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/Adapter/gencode_usingcollectionclasses_adapter.htm

You can create a collection of entities of the correct type, and save the collection.. This will insert all of the entities.

Unless you are actually talking about bulk inserting many rows (1 million for example) using SQL servers bulk load functionality - LLBLGen does not have native support for this.

Matt

Hi, exactly am talking about inserting many rows. How do I achieve this?

Can I use an array and loop through or is there any other alternate?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 07-Jul-2010 08:18:44   

I think Matt has already answered you.

To insert some entities, you put them in a collection and save the collection, they will be inserted one after the other in a transaction. So you don't have to loop on anything.

But if you are talking about Millions of records, then we recommend not using LLBLGen for this. Just go for ADO.NET's SqlBulkCopy class.

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 07-Jul-2010 08:25:08   

Walaa wrote:

I think Matt has already answered you.

To insert some entities, you put them in a collection and save the collection, they will be inserted one after the other in a transaction. So you don't have to loop on anything.

But if you are talking about Millions of records, then we recommend not using LLBLGen for this. Just go for ADO.NET's SqlBulkCopy class.

Dear Walaa,

What I wanted to know is for multiple row insert on single table, can I create an array and loop through instead of SqlBulkCopy.

And I am trying to insert data not copy from one table to another.

Example: I have a datagrid consisting of user transactions. I want to save this grid data in table. or say i have a data table with 100 records which i want to insert into a table

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 07-Jul-2010 08:41:53   

Create an entity for each row you want to insert and add this entity to a collection then save the collection. You don't need to create an aray and loop through.

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 07-Jul-2010 08:45:59   

Walaa wrote:

Create an entity for each row you want to insert and add this entity to a collection then save the collection. You don't need to create an aray and loop through.

Sounds good. Is there way to create dynamic entities which can be destroyed once job is done?

Reason is the number of rows are not constant. it depends on how many rows of data user wants to insert

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 07-Jul-2010 08:59:24   

You don't need to define the size of the EntityCollection when you create it. So the size is dynamic.

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 07-Jul-2010 09:07:56   

Walaa wrote:

You don't need to define the size of the EntityCollection when you create it. So the size is dynamic.

Ok Let me try in case of problems, I will revert back

yna
User
Posts: 3
Joined: 23-Feb-2010
# Posted on: 21-Jul-2010 19:00:14   

Hi Walaa,

I have read that Oracle forall loop is 30 times faster than for loop.

//for all representation FORALL i in products_tab.first .. products_tab.last INSERT INTO products VALUES products_tab(i); end

//for representation FOR i in products_tab.first .. products_tab.last INSERT INTO products VALUES products_tab(i); end

http://www.dba-oracle.com/oracle_news/news_plsql_forall_performance_insert.htm

When I use SaveMulti(), which of these is used by LLBLGEN, for or forall?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-Jul-2010 07:25:11   

No one.

LLBLGen performs simple _INSERT INTO .... VALUES(....) _ for each entity to insert. They all are committed in a single transaction.

David Elizondo | LLBLGen Support Team