dOOdads MarkAsDeleted might mislead you.

For everyone who starts using MyGeneration.dOOdads (and suffices it to read the quick reference), a problem might happen when deleting multiple rows through iteration (as shown below) - some rows don’t get deleted.

Places places = new Places();
places.Where.Name.Value = "ABC%";
places.Where.Name.Operator = WhereParameter.Operand.Like;
places.Query.Load();
if(places.RowCount > 0)
{
   places.Rewind();
   do
   {
      places.MarkAdDeleted();
   } while( places.MoveNext()) ;
   places.Save();
}

Reason: You should not use MarkAsDeleted in a loop through a collection, because although this method does not physically remove a row (as the quick reference states), it does make the row invisible to a foreach (this is what the reference don’t tell you and is hard to guess). And it is obvious that you shouldn’t do anything inside a foreach that changes the contents of the collection.

Solution: You may instead use the DeleteAll() method, which deletes all rows resulted by your query (or filter) not all rows in the table. And don’t forget to call Save(), by the way.

Places places = new Places();
places.Where.Name.Value = "ABC%";
places.Where.Name.Operator = WhereParameter.Operand.Like;
places.Query.Load();
places.DeleteAll();
places.Save();

Mahdieh

Tags:

Leave a Reply