What should you do?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create a Windows Communication
Foundation (WCF) Data Services service. You deploy the data service to the following URL: http://contoso.com/Northwind.svc.
You add the following code segment. (Line numbers are included for reference only.)

01 var uri = new Uri(@”http://contoso.com/Northwind.svc/”);
02 var ctx = new NorthwindEntities(uri);
03 var categories = from c in ctx.Categories select c;
04 foreach (var category in categories) {
05 PrintCategory(category);
06 …
07 foreach (var product in category.Products) {
08 …
09 PrintProduct(product);
10 }
11 }

You need to ensure that the Product data for each Category object is lazy-loaded. What should you do?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create a Windows Communication
Foundation (WCF) Data Services service. You deploy the data service to the following URL: http://contoso.com/Northwind.svc.
You add the following code segment. (Line numbers are included for reference only.)

01 var uri = new Uri(@”http://contoso.com/Northwind.svc/”);
02 var ctx = new NorthwindEntities(uri);
03 var categories = from c in ctx.Categories select c;
04 foreach (var category in categories) {
05 PrintCategory(category);
06 …
07 foreach (var product in category.Products) {
08 …
09 PrintProduct(product);
10 }
11 }

You need to ensure that the Product data for each Category object is lazy-loaded. What should you do?

A.
Add the following code segment at line 06:
ctx.LoadProperty(category, “Products”);

B.
Add the following code segment at line 08:
ctx.LoadProperty(product, “*”);

C.
Add the following code segment at line 06:
var strPrdUri = string.Format(“Categories({0})?$expand=Products”, category.CategoryID);
var productUri = new Uri(strPrdUri, UriKind.Relative);
ctx.Execute<Product>(productUri);

D.
Add the following code segment at line 08:
var strprdUri= string.format(“Products?$filter=CategoryID eq {0}”, category.CategoryID);
var prodcutUri = new Uri(strPrd, UriKind.Relative);
ctx.Execute<Product>(productUri);

Explanation:
LoadProperty(Object, String) Explicitly loads an object related to the supplied object by the specified navigation property and using the default merge option.

UriKind Enumeration
(http://msdn.microsoft.com/en-us/library/system.urikind.aspx)

RelativeOrAbsolute The kind of the Uri is indeterminate.
Absolute The Uri is an absolute Uri.
Relative The Uri is a relative Uri.



Leave a Reply 1

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


Ed van Gageldonk

Ed van Gageldonk

I have my doubts here.

ctx.LoadProperty(category, “Products”);

I don’t consider this lazy loading (“that the Product data for each Category object is lazy-loaded”).
It is indeed explicit loading as stated in the explanation.

Still A is the best answer, of course.