PrepAway - Latest Free Exam Questions & Answers

Tag: 70-516

Exam 70-516: TS: Accessing Data with Microsoft .NET Framework 4

Which code segment should you insert at line 14?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
The application uses the ADO.NET Entity Framework to model entities.
The conceptual schema definition language (CSDL) file contains the following XML fragment.

<EntityType Name=”Contact”>

<Property Name=”EmailPhoneComplexProperty” Type=”AdventureWorksModel.EmailPhone” Nullable=”false” />
</EntityType>

<ComplexType Name=”EmailPhone”>
<Property Type=”String” Name=”EmailAddress” MaxLength=”50″ FixedLength=”false” Unicode=”true” />
<Property Type=”String” Name=”Phone” MaxLength=”25″ FixedLength=”false” Unicode=”true” />
</ComplexType>

You write the following code segment. (Line numbers are included for reference only.)

01 using (EntityConnection conn = new EntityConnection(“name=AdvWksEntities”))
02 {
03 conn.Open();
04 string esqlQuery = @”SELECT VALUE contacts FROM
05 AdvWksEntities.Contacts AS contacts
06 WHERE contacts.ContactID == 3″;
07 using (EntityCommand cmd = conn.CreateCommand())
08 {
09 cmd.CommandText = esqlQuery;
10 using (EntityDataReader rdr = cmd.ExecuteReader())
11 {
12 while (rdr.Read())
13 {
14 …
15 }
16 }
17 }
18 conn.Close();
19 }

You need to ensure that the code returns a reference to a ComplexType entity in the model named EmailPhone.
Which code segment should you insert at line 14?

What should you do?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
The application connects to two different Microsoft SQL Server 2008 database servers named Server1 and Server2.
A string named sql1 contains a connection string to Server1. A string named sql2 contains a connection string to Server2.

01 using (TransactionScope scope = new
02 …
03 )
04 {
05 using (SqlConnection cn1 = new SqlConnection(sql1))
06 {
07 try{
08 …
09 }
10 catch (Exception ex)
11 {
12 }
13 }
14 scope.Complete();
15 }

You need to ensure that the application meets the following requirements:
* There is a SqlConnection named cn2 that uses sql2.
* The commands that use cn1 are initially enlisted as a lightweight transaction.

The cn2 SqlConnection is enlisted in the same TransactionScope only if commands executed by cn1 do not throw an exception.
What should you do?

What should you do?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
The application contains the following code segment. (Line numbers are included for reference only.)

01 class DataAccessLayer
02 {
03 private static string connString;
04 …
05 …
06 public static DataTable GetDataTable(string command){
07 …
08 …
09 }
10 }

You need to define the connection life cycle of the DataAccessLayer class.
You also need to ensure that the application uses the minimum number of connections to the database.
What should you do?

Which code segment should you insert at line 02?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
The application connects to a Microsoft SQL Server database. The application uses the ADO.NET Entity
Framework to model entities. The database includes objects based on the exhibit. (Click the Exhibit button.)

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

01 using (AdventureWorksEntities advWorksContext = new AdventureWorksEntities()){
02 …
03 }

You need to retrieve a list of all Products from todays sales orders for a specified customer.
You also need to ensure that the application uses the minimum amount of memory when retrieving the list.
Which code segment should you insert at line 02?

Which line of code should you insert at line 09?

The application populates a DataSet object by using a SqlDataAdapter object.
You use the DataSet object to update the Categories database table in the database. You write the following code segment.
(Line numbers are included for reference only.)

01 SqlDataAdapter dataAdpater = new SqlDataAdapter(“SELECT CategoryID, CategoryName FROM Categories”, connection);
02 SqlCommandBuilder builder = new SqlCommandBuilder(dataAdpater);
03 DataSet ds = new DataSet();
04 dataAdpater.Fill(ds);
05 foreach (DataRow categoryRow in ds.Tables[0].Rows)
06 {
07 if (string.Compare(categoryRow[“CategoryName”].ToString(), searchValue, true) == 0)
08 {
09 …
10 }
11 }
12 dataAdpater.Update(ds);

You need to remove all the records from the Categories database table that match the value of the searchValue variable.
Which line of code should you insert at line 09?

Which code segment should you add?

The database contains a table named Categories. The Categories table has a primary key identity column named CategoryID.
The application inserts new records by using the following stored procedure.

CREATE PROCEDURE dbo.InsertCategory
@CategoryName nvarchar(15),
@Identity int OUT
AS
INSERT INTO Categories (CategoryName) VALUES(@CategoryName)
SET @Identity = SCOPE_IDENTITY()
RETURN @@ROWCOUNT

You write the following code segment.

SqlDataAdapter adapter = new SqlDataAdapter(“SELECT categoryID, CategoryName FROM dbo.Categories”,connection);
adapter.InsertCommand = new SqlCommand(“dbo.InsertCategory”, connection);
adapter.InsertCommand.CommandType = commandType.StoredProcedure;
adapter.InsertCommand.Parameters.Add(new SqlParameter(“@CategoryName”, SqlDbType.NVarChar, 15,”CategoryName”));

You need to retrieve the identity value for the newly created record. Which code segment should you add?

Which code segment should you insert at line 02?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
The application connects to a Microsoft SQL Server database. You create the classes shown in the following exhibit:

You add the following code segment to the application. (Line numbers are included for reference only.)

01 public void QueryPlayers (List <League> leagues) {
02 …
03 }

You create a LINQ query to retrieve a collection of Player objects.
You need to ensure that the collection includes all the players from each team and every league. Which code segment should you insert at line 02?


Page 11 of 19« First...910111213...Last »