[Free] New Updated (October) Microsoft 70-516 Real Exam Topic 1, C# Scenario

Ensurepass

 

 


Topic 1, C# Scenario

 

Background

You are updating an existing Microsoft .NET Framework 4 application that includes a data layer built with ADO.NET Entity Framework 4. The application communicates with a Microsoft SQL Server 2008 instance named INST01 on a server named SQL01. The application stores data in a database named Contoso in the INST01 instance.

 

You need to update the existing technology and develop new functionality by using Microsoft Visual Studio 2010.

 

Application and Data Structure

The application tracks bicycle parts as they pass through a factory. Parts are represented by the abstract Part entity and its associated partial classes. Each part has a name stored in the Name field and a unique identifier stored in the Id field.

 

Parts are either components (represented by the Component class) such as chains, wheels, and frames, or finished products (represented by the Product class) such as completed bicycles. The Component class and the Product class derive from the Part class and may contain additional class-specific properties.

 

Parts may have a color (represented by the Color class), but not all parts have a color. Parts may be composed of other parts, and those parts may in turn be composed of other parts; any part represents a tree of the parts that are used to build it. The lowest level of the tree consists of components that do not contain other components.

 

A product is a part that has been completed and is ready to leave the factory. A product typically consists of many components (forming a tree of child parts) but can also be constructed by combining other products and/or components to form a bundled product, such as a bicycle and a helmet that are sold together.

 

Components and products are stored in a database table named Parts by using a table- per-hierarchy (TPH) mapping. Components have a null ProductType field and a non-null PartType field. Products have a non-null ProductType field and a null PartType field.

 

The following diagram illustrates the complete Entity data model diagram (EDMX diagram).

 

clip_image001

 

The following graphic illustrates details of the Part-Color Association.

 

clip_image002

 

The following code segments show relevant portions of the files referenced by the case study items. (Line numbers in the samples below are included for reference only and include a two-character prefix that denotes the specific file to which they belong.)

 

Extension Method.cs

clip_image003

 

Model.edmx

clip_image004

 

Model/Color.cs

clip_image005

 

Model/component.cs

clip_image006

 

Model ContosoEntities.cs

clip_image008

 

Model IName.cs

clip_image009

 

Model Part.cs

clip_image011

 

Model/Product.cs

clip_image012

 

SP_FindObsolete

clip_image014

 

 

QUESTION 1

You are developing a new feature that displays an auto-complete list to users as they type color names. You have an existing ContosoEntities context object named context.

 

To support the new feature you must develop code that will accept a string object named text containing a users partial input and will query the Colors database table to retrieve all color names that begin with that input.

 

You need to create an Entity SQL (ESQL) query to meet the requirement. The query must not be vulnerable to a SQL injection attack.

 

Which code segment should you use?

 

A.

var parameter = new ObjectParameter(“text”, text + “%”);

var result = context.CreateQuery<string>(

“SELECT (c.Name) FROM Colors AS c WHERE c.Name LIKE @text”, parameter);

B.

var parameter = new ObjectParameter(“text”, text + “%”);

var result = context.CreateQuery<string>(

“SELECT VALUE (c.Name) FROM Colors AS c WHERE c.Name LIKE ‘@text'”, parameter);

C.

var parameter = new ObjectParameter(“text”, text + “%”);

var result = context.CreateQuery<string>(

“SELECT VALUE (c.Name) FROM Colors AS c WHERE c.Name LIKE @text”, parameter);

D.

var parameter = new ObjectParameter(“text”, HttpUtility.HtmlEncode(text) + “%”);

var result = context.CreateQuery<string>(

“SELECT (c.Name) FROM Colors AS c WHERE c.Name LIKE ‘@text'”, parameter);

 

Correct Answer: C

Explanation:

Entity SQL supports two variants of the SELECT clause. The first variant, row select, is identified by the SELECT keyword, and can be used to specify one or more values that should be projected out.

Because a row wrapper is implicitly added around the values returned, the result of the query expression is always a multiset of rows.

Each query expression in a row select must specify an alias. If no alias is specified,Entity SQL attempts to generate an alias by using the alias generation rules. The other variant of the SELECT clause, value select, is identified by the SELECT VALUE keyword. It allows only one value to be specified, and does not add a row wrapper. A row select is always expressible in terms of VALUE SELECT, as illustrated in the following example.

ESQL Select

http://msdn.microsoft.com/en-us/library/bb399554.aspx

 

 

QUESTION 2

Refer to the following lines in the case study:

 

PA40 in ModelPart.cs, PR16 in ModelProduct.cs, and CT14 in ModelComponent.cs.

 

The application must create XML files that detail the part structure for any product. The XML files must use the following format:

 

<?xml version=”1.0″ encoding=”utf-8″?>

 

<product name=”Brush” description=”Brush product” productType=”1″>

 

<component name=”Handle” description=”Handle” partType=”2″>

 

<component name=”Screw” description=”Screw” partType=”3″ />

 

<component name=”Wood” description=”Wooden shaft” partType=”45″ />

 

</component>

 

<component name
=”Head” description=”Head” partType=”5″>

 

<component name=”Screw” description=”Screw” partType=”3″ />

 

<component name=”Bristles” description=”Bristles” partType=”4″ />

 

</component>

 

</product>

 

You need to update the application to support the creation of an XElement object having a structure that will serialize to the format shown above.

 

What should you do? (Each correct answer presents part of the solution. Choose two.)

 

A.

Insert the following code segment at line PR16 in ModelProduct.cs:

return new XElement(“product, new XAttribute(“name”, this.Name),

new XElement(“description”, this.Description),

new XElement(“productType”, this.ProductType));

B.

Insert the following code segment at line CT14 in ModelComponent.cs:

return new XElement(“component, new XElement(“name”, this.Name),

new XElement(“description”, this.Description),

new XElement(“partType”, this.PartType));

C.

Insert the following code segment at line PR16 in ModelProduct.cs:

return new XElement(“product, new XElement(“name”, this.Name),

new XElement(“description”, this.Description),

new XElement(“productType”, this.ProductType));

D.

Insert the following code segment at line PR16 in ModelProduct.cs:

return new XElement(“product, new XAttribute(“name”, this.Name),

new XAttribute(“description”, this.Description),

new XAttribute(“productType”, this.ProductType));

E.

Insert the following code segment at line CT14 in ModelComponent.cs:

return new XElement(“component, new XAttribute(“name”, this.Name),

new XElement(“description”, this.Description),

new XElement(“partType”, this.PartType));

F.

Insert the following code segment at line CT14 in ModelComponent.cs:

return new XElement(“component, new XAttribute(“name”, this.Name),

new XAttribute(“description”, this.Description),

new XAttribute(“partType”, this.PartType));

 

Correct Answer: DF

 

 

QUESTION 3

The application must be configured to run on a new development computer.

 

You need to configure the connection string to point to the existing named instance.

 

Which connection string fragment should you use?

 

A.

Data Source=INST01SQL01

B.

Data Source=SQL01INST01

C.

Initial Catalog= INST01SQL01

D.

Initial Catalog= SQL01INST01

 

Correct Answer: B

 

 

QUESTION 4

You are developing a new feature in the application to display a list of all bundled products. You need to write a LINQ query that will return a list of all bundled products.

 

Which query expression should you use?

 

A.

context.Parts

.OfType<Product>()

.ToList()

.Where(p => p.Descendants.Any(d => d is Product))

B.

context.Parts

.Cast<Product>()

.Where(p => p.Descendants.Any(d => d is Product))

C.

context.Parts

.OfType<Product>()

.Where(p => p.Descendants.Any(d => d is Product))

D.

context.Parts

.Cast<Product>()

.ToList()

.Where(p => p.Descendants.Any(d => d is Product))

 

Correct Answer: A

Explanation:

OfType() Filters the elements of an IEnumerable based on a specified type.

Enumerable.OfType<TResult> Method

http://msdn.microsoft.com/en-us/library/bb360913.aspx

 

 

QUESTION 5

You need to write a LINQ query that can be used against a ContosoEntities context object named context to find all parts that have a duplicate name.

 

Which of the following queries should you use? (Each correct answer presents a complete solution. Choose two.)

 

A.

context.Parts.Where(p => context.Parts.Any(q => q.Name == p.Name && p.Id != q.Id));

B.

context.Parts.SelectMany(p => context.Parts .Select(q => p.Name == q.Name && p.Id != q.Id));

C.

context.Parts .Any(p => context.Parts .Any(q => p.Name == q.Name));

D.

context.Parts.GroupBy(p => p.Name) .Where(g => g.Count() > 1) .SelectMany(x => x);

 

Correct Answer: AD

 

 

QUESTION 6

The Entity Data Model file (.edmx file) must be updated to support inheritance mapping for Products and Components.

 

You need to add the following code to the ModelModel.edmx file:

 

The code in line EX243 that maps the Product type

 

The code in line EX250 that maps the Component type

 

What should you do?

 

A.

Insert the following code at line EX243:

<Condition ColumnName=”ProductType” IsNull=”true” /> Insert the following code at line at EX250:

<Condition ColumnName=”PartType” IsNull=”true” />

B.

Insert the following code at line EX243:

<Condition ColumnName=”ProductType” IsNull=”false” /> Insert the following code at line at EX250:

<Condition ColumnName=”PartType” IsNull=”true” />

C.

Insert the following code at line EX243:

<Condition ColumnName=”ProductType” IsNull=”true” /> Insert the following code at line EX250:

<Condition ColumnName=”PartType” IsNull=”true” />

D.

Insert the following code at line EX243:

<Condition ColumnName=”ProductType” IsNull=”false” /> Insert the following code at line at EX250:

<Condition ColumnName=”PartType” IsNull=”false” />

 

Correct Answer: D

 

 

QUESTION 7

You are adding a process to the application. The process performs the following actions:

 

1. Opens a ContosoEntities context object named context1.

 

2. Loads a Part object into a variable named part1.

 

3. Calls the Dispose() method on context1.

 

4. Updates the data in part1.

 

5. Updates the database by using a new ContosoEntities context object named context2.

 

You need to update the database with the changed data from part1.

 

What should you do?

 

A.

Add the following code segment before calling SaveChanges() on context2:

context2.ApplyOriginalValues(“Parts”, part1);

B.

Add the following code segment before calling SaveChanges() on context2:

context2.ApplyCurrentValues(“Parts”, part1);

C.

Add the following code segment before calling SaveChanges() on context2:

context2.Attach(part1); context2.ObjectStateManager.ChangeObjectState(part1, System.Data.EntityState.Modified);

D.

Add the following code segment before calling SaveChanges() on context2:

context2.Attach(part1); context2.ApplyCurrentValues(“Parts”, part1);

 

Correct Answer: C

Explanation:

How to: Apply Changes Made to a Detached Object

http://msdn.microsoft.com/en-us/library/bb896248.aspx

private static void ApplyItemUpdates(SalesOrderDetail originalItem, SalesOrderDetail updatedItem)

{

using (AdventureWorksEntities context = new AdventureWorksEntities())

{

context.SalesOrderDetails.Attach(updatedItem);

// Check if the ID is 0, if it is the item is new.

// In this case we need to chage the state to Added.

if (updatedItem.SalesOrderDetailID == 0)

{

// Because the ID is generated by the database we do not need to

// set updatedItem

.SalesOrderDetailID.

context.ObjectStateManager.ChangeObjectState(updatedItem, System.Data.EntityState.Added);

}

else

{

// If the SalesOrderDetailID is not 0, then the item is not new

// and needs to be updated. Because we already added the

// updated object to the context we need to apply the original values.

// If we attached originalItem to the context

// we would need to apply the current values:

// context.ApplyCurrentValues(“SalesOrderDetails”, updatedItem);

// Applying current or original values, changes the state

// of the attached object to Modified.

context.ApplyOriginalValues(“SalesOrderDetails”, originalItem); }

context.SaveChanges();

}

}

 

 

QUESTION 8

You need to ensure that an exception is thrown when color names are set to less than two characters. What should you do?

 

A.

Add the following method to the Color partial class in ModelColor.cs:

protected override void OnPropertyChanged(string property)

{

if (property == “Name” && this.Name.Length < 2)

throw new ArgumentOutOfRangeException(“Name must be at least two characters”);

}

B.

Add the following attribute to the Name property of the Color class in the entity designer file:

[StringLength(256, MinimumLength = 2)]

C.

Add the following code segment to the ContosoEntities partial class in ModelContosoEntities.cs:

public override int SaveChanges(System.Data.Objects.SaveOptions options)

{

var changes =

this.ObjectStateManager.GetObjectStateEntries(System.Data.EntityState.Added); foreach (var change in changes)

{

if (change.Entity is Color)

if (((Color)change.Entity).Name.Length < 2) throw new ArgumentException(“Name too short”);

}

return base.SaveChanges(options);

}

D.

Add the following method to the Color partial class in ModelColor.cs:

protected override void OnPropertyChanging(string property)

{

if (property == “Name” && this.Name.Length < 2)

throw new ArgumentOutOfRangeException(“Name must be at least two characters”);

}

 

Correct Answer: A

 

 

 

QUESTION 9

The database contains orphaned Color records that are no longer connected to Part records.

 

You need to clean up the orphaned records. You have an existing ContosoEntities context object named context.

 

Which code segment should you use?

 

A.

context.Colors.ToList().RemoveAll(c => !c.Parts.Any()); context.SaveChanges();

B.

var unusedColors = context.Colors.Where(c => !c.Parts.Any()).ToList(); foreach (var unused in unusedColors) { context.DeleteObject(unused); } context.SaveChanges();

C.

var unusedColors = context.Colors.Where(c => !c.Parts.Any()); context.DeleteObject(unusedColors); context.SaveChanges();

D.

context.Colors.TakeWhile(c => !c.Parts.Any()); context.SaveChanges();

 

Correct Answer: B

 

 

QUESTION 10

You have an existing ContosoEntities context object named context. Calling the SaveChanges() method on the context object generates an exception that has the following inner exception:

 

System.Data.SqlClient.SqlException:

 

Cannot insert duplicate key row in object ‘dbo.Colors’ with unique index ‘IX_Colors’.

 

You need to ensure that a call to SaveChanges() on the context object does not generate this exception.

 

What should you do?

 

A.

Override the SaveChanges() method on the ContosoEntities class, call the ObjectStateManager.GetObjectStateEntries(System.Data.EntityState.Added) method, and call the AcceptChanges() method on each ObjectStateEntryobject it returns.

B.

Examine the code to see how Color objects are allocated. Replace any instances of the new Color() method with a call to the ContosoEntities.LoadOrCreate() method.

C.

Add a try/catch statement around every call to the SaveChanges() method.

D.

Remove the unique constraint on the Name column in the Colors table.

 

Correct Answer: B

 

 

QUESTION 11

You add a table to the database to track changes to part names. The table stores the following row values: The username of the user who made the change a part ID the new part name a DateTime value

 

You need to enable detection of unauthorized changes to the row values. You also need to ensure that database users can view the original row values.

 

What should you do?

 

A.

Add a column named signature. Use System.Security.Cryptography.RSA to create a signature for all of the row values. Store the signature in the signature column. Publish only the public key internally.

B.

Add a column named hash. Use System.Security.Cryptography.MD5 to create an MD5 hash of the row values, and store the hash in the hash column.

C.

Use System.Security.Cryptography.DES to encrypt all the row values using an encryption key held by the application.

D.

Use System.Security.Cryptography.RSA to encrypt all the row values. Publish only the public key internally.

 

Correct Answer: A

 

 

QUESTION 12

You have a ContosoEntities context object named context and a Color object stored in a variable named color.

 

You write the following code:

 

context.Colors.DeleteObject(color); context.SaveChanges();

 

When the code runs, it generates the following exception:

 

System.Data.UpdateException:

 

An error occurred while updating the entries. See the inner exception for details. —> System.Data.SqlClient.SqlException:

 

The DELETE statement conflicted with the REFERENCE constraint “FK_PartColor”. The conflict occurred in database “Contoso”, table “dbo.Parts”, column ‘ColorId’.

 

You need to resolve the exception without negatively impacting the rest of the application.

 

What should you do?

 

A.

Add code before the call to the DeleteObject() method to examine the collection of Part objects associated with the Color object and then assign null to the Color property for each Part object.

B.

Add a transaction around the call to the SaveChanges() method and handle the exception by performing a retry.

C.

Change the End2 OnDelete property of the FK_PartColor association from None to Cascade.

D.

In the database, remove the foreign key association between the Parts table and the Colors table, and then update the entity data model.

E.

Change the End1 OnDelete property of the FK_PartColor association from None to Cascade.

 

Correct Answer: A

 

 

QUESTION 13

The application must provide a component part list for any product. The component part list must give the quantity of each distinct part that is required to manufacture that product.

 

You need to create a LINQ expression that delivers a result of type IEnumerable<Tuple<int, Part>> to meet the requirements.

 

Which expression should you use?

 

A.

IEnumerable < Tuple < int , Part>> result = part.Descendants

. GroupBy (p => p)

.Select(g => Tuple.Create ( g.Count (), g.Key ));

B.

IEnumerable < Tuple < int , Part>> result = part.Descendants

. ToDictionary (c => c)

.Select(d => Tuple.Create ( d.Value.Children.Count (), d.Key ));

C.

IEnumerable < Tuple < int , Part>> result = part.Children

. GroupBy (p => p)

.Select(g => Tuple.Create ( g.Count (), g.Key ));

D.

IEnumerable < Tuple < int , Part>> result = part.Children

.Distinct()

. GroupBy (p => p)

.Select(g => Tuple.Create ( g.Count (), g.Key ));

E.

IEnumerable < Tuple < int , Part>> result = part.Descendants

.Distinct()

. GroupBy (p => p) .Select(g => Tuple.Create ( g.Count (), g.Key ));

 

Correct Answer: A

 

 

QUESTION 14

The entity data model must be configured to provide a way to call the sp_FindObsolete stored procedure. The returned data must implement the Descendants property.

 

In Visual Studio 2010, you open the Add Function Import dialog box from the EDMX diagram and enter the information shown in the following graphic.

 

clip_image016

You need to complete the configuration in the dialog box.

 

What should you do?

 

A.

In the Returns a Collection Of area, click Entities and then, in the Entities list, click Component.

B.

In the Returns a Collection Of area, click Scalars and then, in the Scalars list, click string.

C.

Click the Get Column Information button, click Create New Complex Type and then, in the Complex box, enter Parts.

D.

In the Returns a Collection Of area, click Scalars and then, in the Scalars list, click Int32.

 

Correct Answer: A

 

 

QUESTION 15

A performance issue exists in the application. The following code segment is causing a performance bottleneck:

 

var colors = context.Parts.GetColors();

 

You need to improve application performance by reducing the number of database calls.

 

Which code segment should you use?

 

A.

var colors = context.Parts.OfType<Product>().Include(“Parts.Color”).GetColors();

B.

var colors = context.Parts.OfType<Product>().Include(“Product.Color”).GetColors();

C.

var colors = context.Parts.OfType<Product>().Include(“Colors”).GetColors();

D.

var colors = context.Parts.OfType<Product>().Include(“Color”).GetColors();

 

Correct Answer: D

 

 

QUESTION 16

DRAG DROP

The user interface requires that a paged view be displayed of all the products sorted in alphabetical order. The user interface supplies a current starting index and a page size in variables named startlndex and pageSize of type int.

 

You need to construct a LINQ expression that will return the appropriate Parts from the database from an existing ContosoEntities context object named context.

 

You begin by writing the following expression:

 

context.Parts

 

Which query parts should you use in sequence to complete the expression?

 

To answer, move the appropriate actions from the list of actions to the answer area and arrange them in the correct order.

 

clip_image018

 

Correct Answer:

clip_image020

 

 

QUESTION 17

The application UI displays a list of products in alphabetical order. To display each product, the UI requires the va of the product Id field and the product Name field.

 

You need to write a LINO query that returns the product name and unique identifier without retrieving any other database columns. The query must create an anonymous type with a field named ProductName that contains the product name and a field named Id that contains the unique identifier.

 

Which query expression should you write?

 

A.

var productNaraes = from produce in context.Pares.OfType<Produet>()

orderby product.Name ascending

select: product;

B.

var productNames = from product in context.Parts where product is Product

orderby product.Name ascending

< p class="MsoNormal" style="margin: 0cm 0cm 0pt; line-height: normal; text-autospace: ; mso-layout-grid-align: none" align="left">select new {product.Id, ProductName = product.Name};

C.

var produceNanes = from preduce in context.Pares

orderby product.Name ascending

select new { Id = product.Id, ProductName = product.Name };

D.

var productNaraes = from prcduct in context.Parts.OfType<Product>()-ToList()

orderby product.Name ascending

select new { Id – product.Id, ProductNane = product.Name >;

 

Correct Answer: D

 

 

QUESTION 18

The application user interface displays part names or color names in many places as ‘## Name ##’.

 

You need to provide a method named FormattedName() to format part names and color names throughout the application.

 

What should you do?

 

A.

Add the following code segment to the ExtensionMethods class in ExtensionMethods.cs:

public static string FormattedName (this Color entity) {

return string.Format(“## {0} ##”, entity.Name);

}

B.

Add the following code segment to the ExtensionMethods class in ExtensionMethods.cs:

public static string FormattedName (this Part entity) {

return string.Format(“## {0} ##”, entity.Name);

}

C.

Add the following code segment to the ExtensionMethods class in ExtensionMethods.cs:

public static string FormattedName (this IName entity) {

return string.Format(“## {0} ##”, entity.Name);

}

D.

Add the following code segment to the Part class in Part.cs:

public string FormattedName()

{

return string.Format(“## {0} ##”, this.Name);

}

E.

Add the following code segment to the Color class in Color.cs:

public string FormattedName()

 

 

{

return string.Format(“## {0} ##”, this.Name);

}

 

Correct Answer: C

Free VCE & PDF File for Microsoft 70-516 Real Exam

Instant Access to Free VCE Files: MCSE|MCSA|MCITP…
Instant Access to Free PDF Files: MCSE|MCSA|MCITP…