I asked a different question about Nested Transactions and the answer to my question educated me enough to help me realize I was asking the question poorly. So here's a better question.
How can I effectively implement SQL Server Savepoints (link 1, link 2) with a DAL built upon Entity Framework 4.0?
I would LIKE to write the following code and have it work in a way that SQL Server's SAVEPOINTS
public void Bar()
{
using (var ts = new TransactionScope())
{
var ctx = new Context();
DoSomeStuff(ctx);
bool isSuccessful;
using (var spA = new SavePoint("A")) // <-- this object doesn't really exist, I don't think
{
isSuccessful = DoSomeOtherStuff(ctx);
if (isSuccessful)
spA.Complete(); // else rollback bo prior to the beginning of this using block
}
Log(ctx, isSuccessful);
ts.Complete();
}
}
Is there such a way to do anything even close to resembling this, or something else that plays nicely with EF4? (we use custom self-tracking POCO entities)
This isn't quite a full answer, but I suspect something like this might be going down the right path. My problem is that I'm not entirely sure how to get a SqlTransaction while in a TransactionScope.
This would be consumed as such, very similarly to a TransactionScope: