[Free] New Updated (October) Microsoft 70-516 Real Exam

Ensurepass

 

Topic 2, VB 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 Database Storage

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 component s (represented by the Component class) such as chains, wheels, and frames, or finished product s (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 p art represents a tree of the parts that are used to build it, The lowest level of the tree consists of c omponents that do not contain other component s.

 

A p roduct is a p art that has been completed and is ready to leave the factory. A p roduct typically consists of many c omponents (forming a tree of child p arts) but can also be constructed by combining other p roducts and/or c omponents to form a bundled p roduct, such as a bicycle and a helmet that are sold together.

 

C omponents and p roducts 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 detail s 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 Methods.vb

clip_image004

 

Model.edmx

clip_image005

 

Model/Color.vb

clip_image006

 

Model/Component.vb

clip_image007

 

ModelContosoEntities.vb

clip_image009

 

Model IName.vb

clip_image010

 

Model Part.vb

clip_image012

 

Model Product.vb

clip_image013

 

sp_FindObsolete

clip_image014

 

 

 

 

 

 

 

 

 

 

 

 

 

QUESTION 1

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_image015

 

You need to complete the configuration in the dialog box.

 

What should you do?

 

A.

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

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 Entities and then, in the Entities list, click Component.

 

Correct Answer: D

 

 

 

 

 

 

 

 

QUESTION 2

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.

Initial Catalog= INST01SQL01

B.

Initial Catalog= SQL01INST01

C.

Data Source=INST01SQL01

D.

Data Source=SQL01INST01

 

Correct Answer: D

 

 

QUESTION 3

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 Color class in Color.vb:

Public Function FormattedName() As String Return String.Format(“## {0} ##”, Me.Name)

End Function

B.

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

<System.Runtime.CompilerServices.Extension()> _ Public Function

FormattedName(ByVal entity As IName) As String Return String.Format(“## {0} ##”, entity.Name)

End Function

C.

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

<System.Runtime.CompilerServices.Extension()> Public Function

FormattedName(ByVal entity As Color) As String Return String.Format(“## {0} ##”, entity.Name)

End Function

D.

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

<System.Runtime.CompilerServices.Extension()> Public Function

FormattedName(ByVal entity As Part) As String Return String.Format(“## {0} ##”, entity.Name)

End Function

E.

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

Public Function FormattedName() As String Return String.Format(“## {0} ##”, Me.Name)

End Function

 

Correct Answer: B

 

 

 

 

 

 

 

 

 

 

QUESTION 4

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 Integer.

 

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.Paces

 

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_image017

 

Correct Answer:

clip_image019

 

 

 

 

 

 

QUESTION 5

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

 

Dim colors = context.Parts.GetColors()

 

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

 

Which code segment should you use?

 

A.

Dim colors = context.Parts.OfType(Of Product).Include(“Product.Color”).GetColors()

B.

Dim colors = context.Parts.OfType(Of Product).Include(“Colors”).GetColors()

C.

Dim colors = context.Parts.OfType(Of Product).Include(“Parts.Color”).GetColors()

D.

Dim colors = context.Parts.OfType(Of Product).Include(“Color”).GetColors()

 

Correct Answer: D

 

 

QUESTION 6

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(Function(p) context.Parts.

Any(Function(q) q.Name = p.Name AndAlso p.Id <> q.Id))

B.

context.Parts.GroupBy(Function(p) p.Name).

Where(Function(g) g.Count() > 1).

SelectMany(Function(x) x)

C.

context.Parts.SelectMany(Function(p) context.Parts.

Select(Function(q) p.Name = q.Name AndAlso p.Id <> q.Id))

D.

context.Parts.

Any(Function(p) context.Parts.

Any(Function(q) p.Name = q.Name))

 

Correct Answer: AB

 

 

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.Attach(part1) context2.ApplyCurrentValues(“Parts”, part1)

B.

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

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

C.

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

context2.ApplyCurrentValues(“Parts”, part1)

D.

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

context2.ApplyOriginalValues(“Parts”, part1)

 

Correct Answer: B

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

Refer to the following lines in the case study: PA42 in ModelPart.vb, PR16 in ModelProduct.vb, and CT14 in ModelComponent.vb.

 

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 9

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 in the hash column.

C.

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

D.

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

 

Correct Answer: A

 

 

QUESTION 10

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 attribute to the Name property of the Color class in the entity designer file:

<StringLength(256, MinimumLength:=2)>

B.

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

Protected Overrides Sub OnPropertyChanged(ByVal [property] As String)

If ([property] = “Name” AndAlso Me.Name.Length < 2) Then

Throw New ArgumentOutOfRangeException(“Name must be at least two characters”)

End If

End Sub

C.

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

Public Overrides Function SaveChanges(ByVal options As

System.Data.Objects.SaveOptions) As Integer Dim changes =

Me.ObjectStateManager.GetObjectStateEntries(System.Data.EntityState.Added)

For Each change In changes

If (TypeOf change.Entity Is Color) Then

If DirectCast(change.Entity, Color).Name.Length < 2 Then

Throw New ArgumentException(“Name too short”)

End If

End If

Next

Return SaveChanges(options)

End Function

D.

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

Protected Overrides Sub OnPropertyChanging(ByVal [property] As String)

If ([property] = “Name” AndAlso Me.Name.Length < 2) Then

Throw New ArgumentOutOfRangeException(“Name must be at least two characters”)

End If

End Sub

 

Correct Answer: D

 

 

QUESTION 11

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.

Dim parameter = New ObjectParameter(“text”, HttpUtility.HtmlEncode(text) & “%”)

Dim result = context.CreateQuery(Of String)(

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

B.

Dim parameter = New ObjectParameter(“text”, text & “%”)

Dim result = context.CreateQuery(Of String)(

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

C.

Dim parameter = New ObjectParameter(“text”, text & “%”)

Dim result = context.CreateQuery(Of String)(

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

D.

Dim parameter = New ObjectParameter(“text”, text & “%”)

Dim result = context.CreateQuery(Of String)(

“SELECT VALUE (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 12

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.

Add a Try/Catch statement around every call to the SaveChanges() method.

B.

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

C.

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.

D.

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

 

Correct Answer: C

 

 

QUESTION 13

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().

Cast(Of Product)().

Where(Function(p) p.Descendants.Any(Function(d) TypeOf d Is Product))

B.

context.Parts.

Cast(Of Product)().

ToList().

Where(Function(p) p.Descendants.Any(Function(d) TypeOf d Is Product))

C.

context.Parts.

OfType(Of Product)().

Where(Function(p) p.Descendants.Any(Function(d) TypeOf d Is Product))

D.

context.Parts.

OfType(Of Product)().

ToList().

Where(Function(p) p.Descendants.Any(Function(d) TypeOf d Is Product))

 

Correct Answer: D

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 14

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.

Dim unusedColors = context.Colors.Where(Function(c) Not c.Parts.Any())

context.DeleteObject(unusedColors)

context.SaveChanges()

B.

Dim unusedColors = context.Colors.Where(Function(c) Not c.Parts.Any()).ToList()

For Each unused As Color In unusedColors

context.DeleteObject(unused)

Next

context.SaveChanges()

C.

context.Colors.ToList().RemoveAll(Function(c) Not c.Parts.Any())

context.SaveChanges()

D.

context.Colors.TakeWhile(Function(c) Not c.Parts.Any())

context.SaveChanges()

 

Correct Answer: B

 

 

QUESTION 15

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:

 

clip_image021The code in line EX243 that maps the Product type

clip_image021[1]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=”true” />

Insert the following code at line EX250:

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

C.

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” />

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< /font>

 

 

QUESTION 16

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(Of Tuple(Of Integer, Part))to meet the requirements.

 

Which expression should you use?

 

A.

Dim result As IEnumerable ( Of Tuple (Of Integer, Part)) = part.Descendants .

ToDictionary ( Function(c) c).

Select(Function(d) Tuple.Create ( d.Value.Children.Count (), d.Key ))

B.

Dim result As IEnumerable ( Of Tuple (Of Integer, Part)) = part.Children .

GroupBy ( Function(p) p).

Select(Function(g) Tuple.Create ( g.Count (), g.Key ))

C.

Dim result As IEnumerable ( Of Tuple (Of Integer, Part)) = part.Descendants .

GroupBy ( Function(p) p).

Select(Function(g) Tuple.Create ( g.Count (), g.Key ))

D.

Dim result As IEnumerable ( Of Tuple (Of Integer, Part)) = part.Descendants .

Distinct( ).

GroupBy ( Function(p) p).

Select(Function(g) Tuple.Create ( g.Count (), g.Key ))

E.

Dim result As IEnumerable ( Of Tuple (Of Integer, Part)) = part.Children .

Distinct( ).

GroupBy ( Function(p) p).

Select(Function(g) Tuple.Create ( g.Count (), g.Key ))

 

Correct Answer: C

 

 

QUESTION 17

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.

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

C.

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

D.

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

E.

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

 

Correct Answer: A

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…