PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You use Microsoft .NET Framework 4.0 and the Entity Framework to develop an application.
You create an Entity Data Model that has an entity named Customer. You set the optimistic concurrency option for Customer.
You load and modify an instance of Customer named loadedCustomer, which is attached to an ObjectContext named context.

You need to ensure that if a concurrency conflict occurs during a save, the application will load up-to-date values from
the database while preserving local changes. Which code segment should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
try
{
context.SaveChanges();
}
catch(EntitySqlException ex)
{
context.Refresh(RefreshMode.StoreWins, loadedCustomer);
}

B.
try
{
context.SaveChanges();
}
catch(OptimisticConcurrencyException ex)
{
context.Refresh(RefreshMode.ClientWins, loadedCustomer);
}

C.
try
{
context.SaveChanges();
}
catch(EntitySqlException ex)
{
context.Refresh(RefreshMode.ClientWins, loadedCustomer);
}

D.
try
{
context.SaveChanges();
}
catch(OptimisticConcurrencyException ex)
{
context.Refresh(RefreshMode.StoreWins, loadedCustomer);
}

Explanation:
EntitySqlException Represents errors that occur when parsing Entity SQL command text.
This exception is thrown when syntactic or semantic rules are violated.
System.Object
System.Exception
System.SystemException
System.Data.DataException
System.Data.EntityException
System.Data.EntitySqlException

OptimisticConcurrencyException The exception that is thrown when an optimistic concurrency violation occurs.
System.Object
System.Exception
System.SystemException
System.Data.DataException
System.Data.UpdateException
System.Data.OptimisticConcurrencyException

Optimistic Concurrency (ADO.NET)
(http://msdn.microsoft.com/en-us/library/aa0416cz.aspx)

http://msdn.microsoft.com/en-us/library/system.data.objects.refreshmode.aspx
http://msdn.microsoft.com/en-us/library/bb738618.aspx


Leave a Reply