Which code segment should you insert at line 06?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to develop an application
that uses the Entity Framework. You create the following Entity Data Model.

You write the following code. (Line numbers are included for reference only.)
01using (var context = new AdventureWorksLTEntities())
02{
03Customer cust = context.Customers.First();
04cust.CompanyName = “Contoso”;
05int count = 0;
06
07}
The changes to the cust entity must be saved. If an exception is thrown, the application must retry
the save 3 times. You need to add a code segment to meet the requirements. Which code segment
should you insert at line 06?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to develop an application
that uses the Entity Framework. You create the following Entity Data Model.

You write the following code. (Line numbers are included for reference only.)
01using (var context = new AdventureWorksLTEntities())
02{
03Customer cust = context.Customers.First();
04cust.CompanyName = “Contoso”;
05int count = 0;
06
07}
The changes to the cust entity must be saved. If an exception is thrown, the application must retry
the save 3 times. You need to add a code segment to meet the requirements. Which code segment
should you insert at line 06?

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.ObjectStateManager.GetObjectStateEntry
(cust).OriginalValues.IsDBNull(0))
{
if (count++ > 2)
{
break;
}
context.SaveChanges();
}



Leave a Reply 0

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