views:

30

answers:

1

if the code look like:

dim db = new context.mytable
db.somefield = something
context.insertonsubmit(db )
try
   context.save
catch ex as exception
   ''----????
end try

how to I remove db from the context if it goes into the catch?

A: 

One idea would be to wrap the whole process in the try catch, so the if an exception is thrown the context gets disposed thus object is no longer in the context., something like:

try
   dim context = new //LINQ-To-SQL context
   dim db = new context.mytable
   db.somefield = something
   context.insertonsubmit(db )
   context.save
catch ex as exception
   context.dispose();
end try

Note: I have not tried this so you will have to test it.

Nathan W