I’m currently working on a small project to learn Linq where I want to create a large SDF database for a windows phone application on my desktop machine. The application I want to create takes a text files with tab delimited entries and should insert them into the SDF file. There are around 900000 lines in the file. Currently I’m inserting them this way:
ConcurrentBag<Entry> data = new ConcurrentBag<Entry>();
Parallel.ForEach<DictCCParser.Entry>(entries, e =>
{
Entry entry = new Entry { LanguageOne = e.Lang1, LanguageTwo = e.Lang2, GroupId = groupIds[e.Group] };
data.Add(entry);
});
Console.WriteLine("Inserting data");
db.Entries.InsertAllOnSubmit(data);
db.SubmitChanges();
The problem is, that LINQ seems to create 900000 separate INSERT INTO statements. I’ve read that it is possible to use bulk insert, however every implementation I cam across needed a SQLCE 4.0 file. I tried to create a huge query containing all the Inserts like
INSERT INTO Entries(LanguageOne, LanguageTwo, Group) VALUES (...),(...),(...)
But apparently SqlCE doesn’t work with multiple inserts. Is there a way to speed up this code?
You can use my SqlCeBulkCopy library, for Windows Phone the database MUST be 3.5 format – http://sqlcebulkcopy.codeplex.com