SubSonic Quickie - How to Delete using the Query Tool

October 29, 2007 12:37 by Dominick
Here's a quick little bit of code that shows how to delete records in your database using SubSonic's Query Tool. I know you can write this is fewer lines of code, but I think this shows a little more clearly what's going on.
Query qryDelete = new Query(DeliverableCategoriesSelected.Schema);
qryDelete.QueryType = QueryType.Delete;
// You can also do the following line in this way: qryDelete.WHERE("ProductId", productId);
qryDelete.WHERE(Products.Columns.ProductId, productId); //where productId equals the product ID number you want to delete
qryDelete.Execute();
SubSonic also supports logical deletes so if you have your tables setup with the extra fields (isDeleted being the most important) than you record will not disappear. You can still do that with the "Destroy" method if you really feel the need to kill something.



Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading