tags:

views:

67

answers:

1

How to get the affected rows number of Linq To Sql?

I use Linq To Sql to delete a batch of records in the sql server 2005.

How can I get the affected rows number?

And How can I know how many records have been deleted if that is something wrong happened in the batch delete?

+1  A: 
using (DataContext db = new DataContext())
{
    db.Stuff.InsertOnSubmit(stuff);
    int rowsInserted = db.GetChangeSet().Inserts.Count;
    db.SubmitChanges();
}

The GetChangeSet() method also contains updates & deletes, if that's what you need.

TheQ