Which code segment should you use?
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to develop an application
that uses the Entity Framework. The application has an entity model that includes SalesTerritory and
SalesPerson entities as shown in the following diagram.
You need to calculate the total bonus for all sales people in each sales territory. Which code segment
should you use?
Which line of code should you insert at line 9?
You use Microsoft .NET Framework 4 to develop an application that connects to a Microsoft SQL
Server 2008 database. You add the following table to the database.
CREATE TABLE ObjectCache (
Id INT IDENTITY PRIMARY KEY,
SerializedObjectData XML )
You write the following code segment to retrieve records from the ObjectCache table. (Line numbers
are included for reference only.)
01Dim s As String = GetConnectStringFromConfigFile(“xmldb”)
02Using conn As New SqlConnection(s)
03Using cmd As New SqlCommand(
04″select * from ObjectCache”, conn))
05
06conn.Open()
07Dim rdr As SqlDataReader = cmd.ExecuteReader()
08While rdr.Read()
09
10DeserializeObject(obj)
11End While
12End Using
13End Using
You need to retrieve the data from the SerializedObjectData column and pass it to a method named
DeserializeObject. Which line of code should you insert at line 9?
Which code segment should you insert at line 02?
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 model entities. The database includes objects based on the exhibit. The application
includes the following code segment. (Line numbers are included for reference only.)
01 using (AdventureWorksEntities context = new AdventureWorksEntities()){
02
03 foreach (SalesOrderHeader order in customer.SalesOrderHeader){
04Console.WriteLine(String.Format(“Order: {0} “, order.SalesOrderNumber));
05 foreach (SalesOrderDetail item in order.SalesOrderDetail){
06Console.WriteLine(String.Format(“Quantity: {0} “, item.Quantity));
07Console.WriteLine(String.Format(“Product: {0} “, item.Product.Name));
08}
09}
10}
You want to list all the orders for a specified customer. You need to ensure that the list contains the
following fields:
“Order number
“Quantity of products
“Product name
Which code segment should you insert at line 02?
Which code segment should you insert at line 05?
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. You
use the ADO.NET Entity Framework to model entities. You write the following code segment. (Line
numbers are included for reference only.)
01public partial class SalesOrderDetail : EntityObject
02{
03partial void OnOrderQtyChanging(short value)
04{
05
06{
07…
08}
09}
10}
You need to find out whether the object has a valid ObjectStateEntry instance. Which code segment
should you insert at line 05?
Which code segment should you insert at line 07?
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. The database includes a table named
dbo. Documents that contains a column with large binary data. You are creating the Data Access
Layer (DAL). You add the following code segment to query the dbo.Documents table. (Line numbers
are included for reference only.)
01 public void LoadDocuments(DbConnection cnx)
02 {
03 var cmd = cnx.CreateCommand();
04 cmd.CommandText = “SELECT * FROM dbo.Documents”;
05 …
06 cnx.Open();
07 …
08 ReadDocument(reader);
09 }
You need to ensure that data can be read as a stream. Which code segment should you insert at line
07?
You need to ensure that entities changed in offline mode can be successfully updated in the data store
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The
application uses the ADO.NET Entity Framework to model entities. The application allows users to
make changes while disconnected from the data store. Changes are submitted to the data store by
using the SubmitChanges method of the DataContext object. You receive an exception when you call
the SubmitChanges method to submit entities that a user has changed in offline mode. You need to
ensure that entities changed in offline mode can be successfully updated in the data store. What
should you do?
Which XPath expression should you use?
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The
application contains the following XML fragment.
<ApplicationMenu>
<MenuItem name=”File”>
<MenuItem name=”New”>
<MenuItem name=”Project” />
<MenuItem name=”Web Site” />
</MenuItem>
<MenuItem name=”Open”>
<MenuItem name=”Project” />
<MenuItem name=”Web Site” />
</MenuItem>
<MenuItem name=”Save” />
</MenuItem>
<MenuItem name=”Edit”>
<MenuItem name=”Cut” />
<MenuItem name=”Copy” />
<MenuItem name=”Paste” />
</MenuItem>
<MenuItem name=”Help”>
<MenuItem name=”Help” />
<MenuItem name=”About” />
</MenuItem>
</ApplicationMenu>
The application queries the XML fragment by using the XmlDocument class. You need to select all
the descendant elements of the MenuItem element that has its name attribute as File. Which XPath
expression should you use?
You need to add a function that returns the number of years since a person was hired
You use Microsoft visual studio 2010 and Microsoft NET Framework 4 to create an Application. The
application uses the ADO NFT Entity Framework to model entities. The model includes the entity
shown in the following exhibit.
You need to add a function that returns the number of years since a person was hired. You also need
to ensure that the function can be used within LINQ to Entities queries. What should you do?
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 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?