I used both of your suggestions (keeping a connection open and unit of work) in my single table sample, and it certainly ran faster (but nowhere near as fast as sqlcmd). However, now that I'm writing my production app, the performance is less than ideal again.
We are loading 1 parent table (employee) and 1 child table (employee history). The employee table has 2000 rows, and the employee history table has 6000 rows. Via the command line using sqlcmd, I can insert the 8000 rows into these 2 tables in a few seconds.
However, via llblgen with no transactions and a single open connection (keepConnectionOpen = true) as you suggested, the 8000 rows can take up to 4 minutes. Same performance with a UnitOfWork. Here's a very simple example of inserting 8000 rows ... like my production table, this runs for 4 minutes:
String connectString = "SERVER=Computer\\SqlExpress; DATABASE=TESTDB; Integrated Security=SSPI;";
_adapter = new DataAccessAdapter(connectString,true);
EmployeeEntity llblEmployee;
EmpHistoryEntity llblEmpHistory;
for (int i = 0; i < 2000; i++)
{
llblEmployee = new EmployeeEntity(); //primary key is IDENTITY column
llblEmployee.Num = i.ToString();
adapter.SaveEntity(llblEmployee, true);
for (int j = 0; j < 3; j++)
{
llblEmpHistory = new EmpHistoryEntity(); //pk is IDENTITY column
llblEmpHistory.EmployeeId = llblEmployee.Id;
llblEmpHistory.Descr = j.ToString();
adapter.SaveEntity(llblEmpHistory);
}
}
Any thoughts? What am I doing wrong? What do other people do if they have thousands or millions or rows to insert?
Thank you very much,
Josh Lindenmuth
BTW - sorry for the code format above, I couldn't figure out how to add spaces or tabs.