You need to ensure that the Product data for each Category object is lazy-loaded

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 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
04 select c;
05 foreach (var category in categories) {
06 PrintCategory(category);
07
08 foreach (var product in category.Products) {
09
10 PrintProduct(product);
11 }
12 }
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 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
04 select c;
05 foreach (var category in categories) {
06 PrintCategory(category);
07
08 foreach (var product in category.Products) {
09
10 PrintProduct(product);
11 }
12 }
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 07.
ctx.LoadProperty(category, “Products”);

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

C.
Add the following code segment at line 07.
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 09.
var strPrdUri = string.Format(“Products?$filter=CategoryID eq {0}”, category.CategoryID);
var productUri = new Uri(strPrdUri, 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 0

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