Reputation: 2055
I'm using LINQ-to-Sql, and I wrote a block to delete a record in database. Executenonquery returns an integer value, and with this value we can find if this record is deleted or not. But how can we do that with Linq? for example in my code:
aspnetdbDataContext aspdb = new aspnetdbDataContext();
var res=from p in aspdb.TrackPoints
where p.RouteFK==routeId
select p;
aspdb.TrackPoints.DeleteOnSubmit(res.First());
aspdb.SubmitChanges();
Upvotes: 0
Views: 186
Reputation: 111
MSDN: SubmitChanges starts a transaction and will roll back if an exception occurs while SubmitChanges is executing
.
So I would guess that if SubmitChanges throws
an exception, the changes has not been made.
Upvotes: 1
Reputation: 13582
System.Data.Linq.ChangeSet cs = aspdb.GetChangeSet();
bool IsDeleted = cs.Deletes.Count() == 0;
here if cs.Deletes is equal to zero it means everything has been ok and the row is deleted but if it is greater than zero, it mean that there are some records that have not been deleted successfully
Upvotes: 0