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

Ensurepass

 

QUESTION 31

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application connects to a Microsoft SQL Server database. You create a DataSet object in the application. You add two DataTable objects named App_Products and App_Categories to the DataSet. You add the following code segment to populate the DataSet object. (Line numbers are included for reference only.)

 

01 public void Fill(SqlConnection cnx, DataSet ds) {

 

02

 

03 var cmd = cnx.CreateCommand();

 

04 cmd.CommandText = “SELECT * FROM dbo.Products; ” + “SELECT * FROM dbo.Categories”;

 

05 var adapter = new SqlDataAdapter(cmd);

 

06

 

07 }

 

You need to ensure that App_Products and App_Categories are populated from the dbo.Products and dbo. Categories database tables. Which code segment should you insert at line 06?

 

A.

adapter.Fill(ds, “Products”); adapter.Fill(ds, “Categories”);

B.

adapter.Fill(ds.Tables[“App_Products”]);

adapter.Fill(ds.Tables[“App_Categories”]);

C.

adapter.TableMappings.Add(“Table”, “App_Products”);

adapter.TableMappings.Add(“Table1”, “App_Categories”);

adapter.Fill(ds);

D.

adapter.TableMappings.Add(“Products”, “App_Products”);

adapter.TableMappings.Add(“Categories”, “App_Categories”);

adapter.Fill(ds);

 

Correct Answer: C

Explanation:

Table Mapping in ADO.NET

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

 

 

 

QUESTION 32

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to develop an application that uses the Entity Framework. You create an Entity Data Model (EDM) named Model. You need to ensure that the Storage Schema Definition Language (SSDL) of the EDM can be modified without rebuilding the application. What should you do?

 

A.

Set the Metadata Artifact Processing property to Embed in Output Assembly and use the following connection string.

metadata=res://*/Model.csdl|res://*/Model.ssdl|

res://*/Model.msl;

provider=System.Data.SqlClient;

provider connection string=”& “

B.

Set the Metadata Artifact Processing property to Copy to Output Directory and use the following connection string.

metadata=res://*/Model.csdl|res://*/Model.ssdl|

res://*/Model.msl;

provider=System.Data.SqlClient;

provider connection string& =”& “

C.

Set the Metadata Artifact Processing property to Embed in Output Assembly and use the following connection string.

metadata=.Model.csdl|.Model.ssdl|.Model.msl;

provider=System.Data.SqlClient;

provider connection string=”& “

D.

Set the Metadata Artifact Processing property to Copy to Output Directory and use the following connection string.

metadata=.Model.csdl|.Model.ssdl|.Model.msl;

provider=System.Data.SqlClient;

provider connection string& =”& “

 

Correct Answer: D

Explanation:

How to: Copy Model and Mapping Files to the Output Directory (Entity Data Model Tools)

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

 

 

QUESTION 33

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application connects to a Microsoft SQL Sever 2008 database. The database includes a table that contains information about all the employees. The database table has a field named EmployeeType that identifies whether an employee is a Contractor or a Permanent employee. You declare the employee entity base type. Yo create a new Association entity named Contractor that inherits the Employee base type. You need to ensure that all Contractors are bound to the Contractor class. What should you do?

 

A.

Modify the .edmx file to include the following line of code. <NavigationProperty Name=’Type’ FromRole=”EmployeeType’ ToRole”Contractor”/>

B.

Modify the .edmx file to include the following Iine of code. <Condition ColumnName=”EmployeeType” Value=”Contractor”/>

C.

Use the Entity Data Model Designer to set up an association between the Contractor class and EmployeeType

D.

Use the Entity Data Model Designer to set up a referential constraint between the primary key of the Contractor class and ErnployeeType

 

Correct Answer: B

Explanation:

<Association Name=”FK_OrderDetails_Orders1″>

<End Role=”Orders” Type=”StoreDB.Store.Orders” Multiplicity=”1″>

<OnDelete Action=”Cascade” />

</End>

<End Role=”OrderDetails” Type=”StoreDB.Store.OrderDetails” Multiplicity=”*” />

<ReferentialConstraint>

<Principal Role=”Orders”>

<PropertyRef Name=”ID” />

</Principal>

<Dependent Role=”OrderDetails”>

<PropertyRef Name=”OrderId” />

</Dependent>

</ReferentialConstraint>

</Association>

 

 

QUESTION 34

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application connects to a Microsoft SQL Server database. The application uses the ADO.NET Entity Framework to manage order data. The application makes a Web service call to obtain orders from an order-tracking system. You need to ensure that the orders are added to the local data store. Which method should you call on the ObjectContext?

 

A.

Attach

B.

AttachTo

C.

AddObject

D.

ApplyCurrentValues

 

Correct Answer: C

Explanation:

ObjectContext.AddObject() Call AddObject on the ObjectContext to add the object to the object context.

Do this when the object is a new object that does not yet exist in the data source. ObjectContext.Attach() Call Attach on the ObjectContext to attach the object to the object context.

Do this when the object already exists in the data source but is currently not attached to the context.

If the object being attached has related objects, those objects will also be attached to the object context.

Objects are added to the object context in an unchanged state. The object that is passed to the Attach method must have a valid EntityKey value. If the object does not have a valid EntityKey value, use the AttachTo method to specify the name of the entity set.

ObjectContext.AttachTo() Call AttachTo on the ObjectContext to attach the object to a specific entity set in the object context or if the object has a null (Nothing in Visual Basic) EntityKey value.

The object being attached is not required to have an EntityKey associated with it. If the object does not have an entity key, then entitySetName cannot be an empty string.

ApplyCurrentValues<TEntity>() method is used to apply changes that were made to objects outside the ObjectContext, such as detached objects that are received by a Web service.

The method copies the scalar values from the supplied object into the object in the ObjectContext that has the same key.

You can use the EntityKey of the detached object to retrieve an instance of this object from the data source.

 

 

 

 

QUESTION 35

You use Microsoft .NET Framework 4 to develop an application that uses the Entity Framework.

 

The application defines the following Entity SQL (ESQL) query, which must be executed against the mode.

 

string prodQuery = “select value p from Products as

 

p where p.ProductCategory.Name = @p0″;

 

You need to execute the query.

 

Which code segment should you use?

 

A.

vac prods = ctx.CreateQuery<Product>(prodQuery, new ObjectPararoeter(“p0”, “Road Bikes”)).ToList();

B.

var prods = ctx.ExecuteStoreCommand(prodQuery, new ObjectParameter(“p0”, “Road Bikes”)).ToList();

C.

var prods = ctx.ExecuteFunction<Product>(prodQuery, new ObjectPararoeter(“p0”, “Road Bikes”)).ToList();

D.

var prods = ctx.ExecuteStoreQuery<Product>(prodQuery, new ObjectPararoeter(“p0”, “Road Bikes”)).ToList();

 

Correct Answer: A

Explanation:

CreateQuery<T> – Creates an ObjectQuery<T> in the current object context by using the specified query string.

ExecuteStoreCommand – Executes an arbitrary command directly against the data source using the existing connection.

ExecuteFunction(String, ObjectParameter[]) – Executes a stored procedure or function that is defined in the data source and expressed in the conceptual model; discards any results returned from the function; and returns the number of rows affected by the execution. ExecuteStoreQuery<TElement>(String, Object[]) – Executes a query directly against the data source that returns a sequence of typed results.

ObjectContext.CreateQuery<T> Method

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

 

 

QUESTION 36

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application connects to a Microsoft SQL Server database. You write the following code segment that executes two commands against the database within a transaction. (Line numbers are included for reference only.)

 

01 using (SqlConnection connection = new SqlConnection(cnnStr)) {

 

02 connection.Open();

 

03 SqlTransaction sqlTran = connection.BeginTransaction();

 

04 SqlCommand command = connection.CreateCommand();

 

05 command.Transaction = sqlTran;

 

06 try {

07 command.CommandText = “INSERT INTO Production.ScrapReason(Name) VALUES(‘Wrong size’)”;

 

08 command.ExecuteNonQuery();

 

09 command.CommandText = “INSERT INTO Production.ScrapReason(Name) VALUES(‘Wrong color’)”;

 

10 command.ExecuteNonQuery();

 

11

 

12 }

 

You need to log error information if the transaction fails to commit or roll back.

 

Which code segment should you insert at line 11?

 

A.

sqlTran.Commit();

}

catch (Exception ex) {

sqlTran.Rollback();

Trace.WriteLine(ex.Message);

}

B.

sqlTran.Commit();

}

catch (Exception ex) {

Trace.WriteLine(ex.Message);

try {

sqlTran.Rollback();

}

catch (Exception exRollback) {

Trace.WriteLine(exRollback.Message);

}

}

C.

catch (Exception ex){

Trace.WriteLine(ex.Message);

try{

sqlTran.Rollback();

}

catch (Exception exRollback){

Trace.WriteLine(exRollback.Message);

}

}

finaly {

sqltran.commit( );

}

D.

catch (Exception ex) {

sqlTran.Rollback();

Trace.WriteLine(ex.Message);

}

finaly {

try {

sqltran.commit( );

}

catch (Exception exRollback) {

Trace.WriteLine(excommit.Message);

}

}

 

Correct Answer: B

Explanation:

A would work, but B is better since we are checking for possible errors during the rollback. C & D would try to do a rollback before a commit?

The finally block is only executed when the application ends, which may not be the appropriate place to put this logic.

Normally, a finally block would contain code to close a Database connection. The finally block executes even if an exception arises.

 

 

QUESTION 37

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application connects to a Microsoft SQL Server 2008 database.

 

You need to use a spatial value type as a parameter for your database query.

 

What should you do?

 

A.

Set the parameters SqlDbType to Udt. Set the parameters UdtTypeName to GEOMETRY.

B.

Set the parameters SqlDbType to Binary.

C.

Set the parameters SqlDbType to Variant.

D.

Set the parameters SqlDbType to Structured. Set the parameters TypeName to GEOMETRY.

 

Correct Answer: A

Explanation:

There are two types of spatial data. The geometry data type supports planar, or Euclidean (flat-earth), data.

The geometry data type conforms to the Open Geospatial Consortium (OGC) Simple Features for SQL Specification version 1.1.0.

In addition, SQL Server supports the geography data type, which stores ellipsoidal (round- earth) data, such as GPS latitude and longitude coordinates. SqlParameter.UdtTypeName Gets or sets a string that represents a user-defined type as a parameter.

CHAPTER 2 ADO.NET Connected Classes

Lesson 2: Reading and Writing Data

Working with SQL Server User-Defined Types (UDTs) (page 105) Spatial types

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

Types of Spatial Data

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

 

 

QUESTION 38

You use Microsoft .NET Framework 4 to develop an application that uses LINQ to SQL.

 

The LINQ to SQL model contains the Product entity. A stored procedure named GetActiveProducts performs a query that returns the set of active products from the database.

 

You need to invoke the stored procedure to return the active products, and you must ensure that the UNQ to SQL context can track changes to these entities.

 

What should you do?

A.

Select the Product entity, view the entity’s property window, and change the Name for the entity to GetActiveProducts.

B.

Add a property named GetActiveProducts to the Product entity.

C.

Navigate to the GetActiveProducts stored procedure in Server Explorer, and drag the procedure onto the Product entity in the LINQ to SQL model designer surface.

D.

Select the Product entity, view the entity’s property window, and change the Source for the entity to GetActiveProducts.

 

Correct Answer: C

Explanation:

http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx

 

 

QUESTION 39

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application connects to a Microsoft SQL Server database and contains a LINQ to SQL data model. The data model contains a function named createCustomer that calls a stored procedure. The stored procedure is also named createCustomer.

 

The createCustomer function has the following signature.

 

createCustomer (Guid customerID, String customerName, String address1)

 

The application contains the following code segment. (Line numbers are included for reference only.)

 

01 CustomDataContext context = new CustomDataContext();

 

02 Guid userID = Guid.NewGuid();

 

03 String address1 = “1 Main Steet”;

 

04 String name = “Marc”;

 

05

 

You need to use the createCustomer stored procedure to add a customer to the database.

 

Which code segment should you insert at line 05?

 

A.

context.createCustomer(userID, name , address1)

B.

context.ExecuteCommand(“createCustomer”, userID, name , address1);

C.

Customer customer = new Customer() {

ID = userID,

Address1 = address1,

Name = name,

};

context.ExecuteCommand(“createCustomer”, customer);

D.

Customer customer = new Customer() {

ID = userID,

Address1 = address1,

Name = name,

};

context.ExecuteQuery(typeof(Customer), “createCustomer”, customer);

Correct Answer: A

Explanation:

CHAPTER 4 LINQ to SQL

Lesson 3: Submitting Changes to the Database

Using Stored Procedures (page 285)

 

 

QUESTION 40

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. Theapplication uses the ADO.NET Entity Framework to model persistence- ignorant entities. The applicationoperates in a disconnected mode.

 

You need to ensure that changes made to local entities while the application is in the disconnected mode are correctly persisted.

 

Which method should you call before persisting changes?

 

A.

ObjectStateEntry.SetModifiedProperty

B.

DataContext.AcceptAllChanges

C.

ObjectStateEntry.AcceptChanges

D.

ObjectContext.Refresh

 

Correct Answer: A

Explanation:

ObjectStateEntry.SetModifiedProperty(string propertyName) Method Marks the specified property as modified.

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…