views:

134

answers:

1

Hi,

Using templates, how can I delete related records from multiple tables in a transaction?

Please advise. Thanks Pankaj

+1  A: 
using (TransactionScope transactionScope = new TransactionScope())
{
  using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
  {
    new SubSonic.Query.Delete<Person>(new MyDB().Provider)
      .Where(PersonTable.IdColumn).IsEqualTo(1)
      .Execute();

    new SubSonic.Query.Delete<Basket>(new MyDB().Provider)
      .Where(BasketTable.IdColumn).IsEqualTo(1)
      .Execute();

    transactionScope.Complete();
  }
}
Adam
thanks. will try this.
AJ