There is Windows Phone 7 app using SQL CE database. I need to delete 1000-2000 rows. There is no other choice than using LINQ To SQL on Windows Phone 7 Mango – SQL CE database.
What I do is extremaly simple (pseudocode):
Entity[] tmp = null;
do
{
tmp = datacontext.mytable.Where( ...expression here ...).Take(200).ToArray();
if (temp.Length > 0)
{
mytable.DeleteAllOnSubmit(tmp);
datacontext.SubmitChanges();
}
} while (temp.Length > 0);
The problem is that deleting 200 rows takes 7 seconds! All time is taken inside datacontext.SubmitChanges().
Is there any way to make it faster?
Any option to use ‘batch delete’? (‘batch_insert’ would be also welcome)
A few technical details:
- DataContext was created by SqlMetal tool and it looks rather heavy.
- Entity has 2 foreign key relations.
Perhaps somebody find it usefull:
Best practises for win phone
I used a few hints from article above plus redesigned algorithm that it tries to modify (recycle) records instead of delete/insert commands. It gave noticeable performance gain, but still comparing the same application on Android and WinPhone it seems WP7 is much slower.
Unfortunatelly I suspect it’s way better to use SqlLite for database heavy apps.