Which code segment should you insert at line 02?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
The application connects to a Microsoft SQL Server database. The application uses the ADO.NET Entity Framework to model entities.
The database includes objects based on the exhibit.
The application includes the following code segment. (Line numbers are included for reference only.)

01 using (AdventureWorksEntities context = new AdventureWorksEntities()){
02 …
03 foreach (SalesOrderHeader order in customer.SalesOrderHeader){
04 Console.WriteLine(String.Format(“Order: {0} “, order.SalesOrderNumber));
05 foreach (SalesOrderDetail item in order.SalesOrderDetail){
06 Console.WriteLine(String.Format(“Quantity: {0} “, item.Quantity));
07 Console.WriteLine(String.Format(“Product: {0} “, item.Product.Name));
08 }
09 }
10 }

You want to list all the orders for a specified customer. You need to ensure that the list contains the following fields:
* Order number
* Quantity of products
* Product name
Which code segment should you insert at line 02?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
The application connects to a Microsoft SQL Server database. The application uses the ADO.NET Entity Framework to model entities.
The database includes objects based on the exhibit.
The application includes the following code segment. (Line numbers are included for reference only.)

01 using (AdventureWorksEntities context = new AdventureWorksEntities()){
02 …
03 foreach (SalesOrderHeader order in customer.SalesOrderHeader){
04 Console.WriteLine(String.Format(“Order: {0} “, order.SalesOrderNumber));
05 foreach (SalesOrderDetail item in order.SalesOrderDetail){
06 Console.WriteLine(String.Format(“Quantity: {0} “, item.Quantity));
07 Console.WriteLine(String.Format(“Product: {0} “, item.Product.Name));
08 }
09 }
10 }

You want to list all the orders for a specified customer. You need to ensure that the list contains the following fields:
* Order number
* Quantity of products
* Product name
Which code segment should you insert at line 02?

A.
Contact customer = context.Contact.Where(“it.ContactID = @customerId”, new ObjectParameter(“@customerId”, customerId)).First();

B.
Contact customer = context.Contact.Where(“it.ContactID = @customerId”, new ObjectParameter(“customerId”, customerId)).First();

C.
context.ContextOptions.LazyLoadingEnabled = true;
Contact customer = (from contact in context.Contact
include(“SalesOrderHeader.SalesOrderDetail”)
select conatct).FirstOrDefault();

D.
Contact customer = (from contact in context.Contact
include(“SalesOrderHeader”)
select conatct).FirstOrDefault();



Leave a Reply 3

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


Mike

Mike

Can someone explain this answer? In particular, why doesn’t the SalesOrderDetail have to be explicitly loaded?

E

E

good point with the lazy loading, but answers C&D do not query for a particular custom correctly, they retrieve the first

John Galt

John Galt

The question asks you to list all orders for a SPECIFIED customer. That automatically rules out C & D, because those don’t query a specific customer. Only A & B pass in ‘customerId’ parameter. The correct answer is B, because A has an “@” prefix before the “@customerId” ObjectParameter name. It should be just “customerId” there.