This project is read-only.

Any ideas to delete all records matching a query? (SOLVED)

Mar 6, 2013 at 9:53 PM
Any ideas of doing a bulk delete?

delete from mytable
where mytable.FirstName like 'Nick%'

When I was trying to do the delete in a foreach loop, I got an error (
Error:10:Internal error : The last object of the commited zone has been deleted but the Zone still have objects : nbobjects=0)

Ultimately though, I'd just like to call odb.Delete<>().Where(d=>d.CacheDate<DateTime.Now);

Ok, Para-phrased that a bit. :)
Mar 7, 2013 at 8:13 AM
Edited Mar 7, 2013 at 8:14 AM
Hello,
you need to firstly query for the objects you want to delete, and then in the same scope of ndatabase you could delete them through the foreach. E.g.:
using (var odb = OdbFactory.Open("dbname.ndb"))
{
    var allObjects = odb.QueryAndExecute<object>().ToList();
    foreach (var itemToDelete in allObjects)
    {
        odb.Delete(itemToDelete);
    }
}
And that's all ;)