Delete query using Subsonic


May 14, 2009
Feedback's a good way to encourage author even if it's a criticize. It's proved you care about the article. Please, leave a comment to let everyone know what you think about this post.

another tip »

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);
// You can also do the following line in this way: qryDelete.WHERE("ProductId", productId);
qryDelete.QueryType = QueryType.Delete;
//where productId equals the product ID number you want to delete
qryDelete.WHERE(Products.Columns.ProductId, productId);
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.

From BloodyFlux

  • Delicious

Some more useful articles for you

Under Category: C#.NET Code
Article
Leave a Reply