You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to develop an application that uses the Entity Framework.
You create the following Entity Data Model.
You add the following code fragment:
using(var context = new AdventureWorksLTEntities())
{
Customer cust = context.Customers.First();
cust.CompanyName = “Contoso”;
int count = 0;
}
The changes to the cust entity must be saved. If an exception is thrown, the application will attempt to save up to 3 times.
If not, an exception is thrown. Which code segment should you use?
A.
while(count++ < 3)
{
try
{
context.SaveChanges();
break;
}
catch(Exception)
{
}
}
B.
while(cust.EntityState == EntityState.Modified)
{
try
{
context.SaveChanges();
}
catch(Exception)
{
if(count++ > 2 && context.Connection.State == ConnectionState.Broken
{
throw new Exception();
}
}
}
C.
while(true)
{
context.SavingChanges += delegate(System.Object o, System.EventArgs e)
{
if(count++ >2)
{
throw new Exception();
}
context.SaveChanges();
}
}
D.
while(context.ObjextStateManager.GetObjectStateEntry(cust).OriginalValues.IsDBNull(0))
{
if(count++ >2)
{
break;
}
context.SaveChanges();
}