Which code segment should you use?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to develop an application.
You use the ADO.NET Entity Framework Designer to model entities. The application includes two
ObjectContext instances named context1 and context2. You need to persist the changes in both
object contexts within a single transaction. Which code segment should you use?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to develop an application.
You use the ADO.NET Entity Framework Designer to model entities. The application includes two
ObjectContext instances named context1 and context2. You need to persist the changes in both
object contexts within a single transaction. Which code segment should you use?

A.
Using scope As New TransactionScope()
context1.SaveChanges()
context2.SaveChanges()
End Using

B.
Using scope As New TransactionScope()
Using scope1 As New _
TransactionScope(TransactionScopeOption.RequiresNew)
context1.SaveChanges()
scope1.Complete()
End Using
Using scope2 As New _
TransactionScope(TransactionScopeOption.RequiresNew)
context2.SaveChanges()
scope2.Complete()
End Using
scope.Complete()
End Using

C.
Using scope As New TransactionScope()
Using scope As New _
TransactionScope(TransactionScopeOption.RequiresNew)

context1.SaveChanges()
End Using
Using scope As New _
TransactionScope(TransactionScopeOption.RequiresNew)
context2.SaveChanges()
End Using
End Using

D.
Using scope As New TransactionScope()
context1.SaveChanges()
context2.SaveChanges()
scope.Complete()
End Using

Explanation:
TransactionScope.Complete Indicates that all operations within the scope are completed
successfully.
TransactionScope Class
(http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx)



Leave a Reply 0

Your email address will not be published. Required fields are marked *