Ensurepass

QUESTION 201

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 load records from the Customers table into a DataSet object named dataset. You need to retrieve the value of the City field from the first and last records in the Customers table. Which code segment should you use?

 

  1. DataTable dt = dataset.Tables[“Customers”];

string first = dt.Rows[0][“City”].ToString();

string last = dt.Rows[dt.Rows.Count – 1][“City”].ToString();

 

  1. DataTable dt = dataset.Tables[“Customers”];

string first = dt.Rows[0][“City”].ToString();

string last = dt.Rows[dt.Rows.Count][“City”].ToString();

 

  1. DataRelation relationFirst = dataset.Relations[0];

DataRelation relationLast = dataset.Relations[dataset.Relations.Count – 1];

string first = relationFirst. childTable.Columns[“City”].ToString();

string last = relationLast.childTable.Columns[“City”].ToString()

 

  1. DataRelation relationFirst = dataset.Relations[0];

DataRelation relationLast = dataset.Relations[dataset.Relations.Count];

string first = relationFirst. childTable.Columns[“City”].ToString();

string last = relationLast.childTable.Columns[“City”].ToString();

 

Correct Answer: A

 

 

QUESTION 202

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 has two DataTable objects that reference the Customers and Orders tables in the database. The application contains the following code segment. (Line numbers are included for reference only.)

 

01 DataSet customerOrders = new DataSet();

02 customerOrders.EnforceConstraints = true;

03 ForeignKeyConstraint ordersFK = new ForeignKeyConstraint(“ordersFK”,

04 customerOrders.Tables[“Customers”].Columns[“CustomerID”],

05 customerOrders.Tables[“Orders”].Columns[“CustomerID”]);

06 …

07 customerOrders.Tables[“Orders”].Constraints.Add(ordersFK);

 

You need to ensure that an exception is thrown when you attempt to delete Customer records that have related Order records. Which code segment should you insert at line 06?

 

  1. ordersFK.DeleteRule = Rule.SetDefault;

  2. ordersFK.DeleteRule = Rule.None;

  3. ordersFK.DeleteRule = Rule.SetNull;

  4. ordersFK.DeleteRule = Rule.Cascade;

 

Correct Answer: B

 

 

QUESTION 203

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 a DataTable named OrderDetailTable that has the following columns:

 

  • ID

  • OrderID

  • ProductID

  • Quantity

  • LineTotal

 

Some records contain a null value in the LineTotal field and 0 in the Quantity field. You write the following code segment. (Line numbers are included for reference only.)

 

01 DataColumn column = new DataColumn(“UnitPrice”, typeof(double));

02 …

03 OrderDetailTable.Columns.Add(column);

 

You need to add a calculated DataColumn named UnitPrice to the OrderDetailTable object. You also need to ensure that UnitPrice is set to 0 when it cannot be calculated. Which code segment should you insert at line 02?

 

  1. column.Expression = “LineTotal/Quantity”;

  2. column.Expression = “LineTotal/ISNULL(Quantity, 1)”;

  3. column.Expression = “if(Quantity > 0, LineTotal/Quantity, 0)”;

  4. column.Expression = “iif(Quantity > 0, LineTotal/Quantity, 0)”;

 

Correct Answer: D

 

 

QUESTION 204

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 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?

 

  1. context.createCustomer(userID, customer1, address1);

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

Customer customer = new Customer() { ID = userID, Address1 = address1, Name = customer1, };

  1. context.ExecuteCommand(“createCustomer”, customer);

Customer customer = new Customer() { ID = userID, Address1 = address1, Name = customer1, };

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

 

Correct Answer: A

 

 

QUESTION 205

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 use the ADO.NET Entity Framework to manage persistence-ignorant entities. You create an ObjectContext instance named context. Then, you directly modify properties on several entities. You need to save the modified entity values to the database. Which code segment should you use?

 

  1. context.SaveChanges(SaveOptions.AcceptAllChangesAfterSave);

  2. context.SaveChanges(SaveOptions.DetectChangesBeforeSave);

  3. context.SaveChanges(SaveOptions.None);

  4. context.SaveChanges();

 

Correct Answer: B

 

 

QUESTION 206

You develop a Microsoft .NET application that uses Entity Framework to store entities in a Microsft SQL Server 2008 database. While the application is disconnected from the database, entities that are modified, are serialized to a local file. The next time the application connects to the database, it retrieves the identity from the database by using an object context named context and stores the entity in a variable named remoteCustomer. The application then serializes the Customer entity from the local file and stores the entity in a variable named localCustomer. The remoteCustomer and the localCustomer variables have the same entity key. You need to ensure that the offline changes to the Customer entity is persisted in the database when the ObjectContext. SaveChanges() method is called. Which line of code should you use?

 

  1. context.ApplyOriginalValues(“Customers”, remoteCustomer);

  2. context.ApplyOriginal
    Values(“Customers”, localCustomer);

  3. context.ApplyCurrentValues(“Customers”, remoteCustomer);

  4. context.ApplyCurrentValues(“Customers”, localCustomer);

 

Correct Answer: D

 

 

QUESTION 207

You use Microsoft .NET framework 4.0 to develop an application that connects to a Microsoft SQL Server 2008 database named AdventureWorksLT. The database resides on an instance named INSTA on a server named SQL01. You need to configure the application to connect to the database. Which connection string should you add to the .config file?

 

  1. Data Source=SQL01; Initial Catalog=INSTA; Integrated Security=true; Application Name=AdventureWorksLT;

  2. Data Source=SQL01; Initial Catalog=AdventureWorksLT; Integrated Security=true; Application Name=INSTA;

  3. Data Source=SQL01INSTA; Initial Catalog=AdventureWorksLT; Integrated Security=true;

  4. Data Source=AdventureWorksLT; Initial Catalog=SQL01INSTA; Integrated Security=true;

Correct Answer: C

 

 

QUESTION 208

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 context = new AdventureWorksEntities())

02 {

03 …

04 foreach (SalesOrderHeader order in customer.SalesOrderHeader)

05 {

06 Console.WriteLine(String.Format(“Order: {0} “, order.SalesOrderNumber));

07 foreach (SalesOrderDetail item in order.SalesOrderDetail)

08 {

09 Console.WriteLine(String.Format(“Quantity: {0} “, item.Quantity));

10 Console.WriteLine(String.Format(“Product: {0} “, item.Product.Name));

11 }

12 }

13 }

 

You want to list all the orders for a specific customer. You need to ensure that the list contains following fields:

 

  • Order number

  • Quantity of products

  • Product name

 

Which code segment should you insert in line 03?

 

  1. Contact customer = context.Contact.Where(“it.ContactID = @customerId”,

new ObjectParameter(“customerId”, customerId)).First();

 

  1. Contact customer = context.Contact.Where(“it.ContactID = @customerId”,

new ObjectParameter(“@customerId”, customerId)).First();

 

  1. Contact customer = (from contact in context.Contact.Include

(“SalesOrderHeader.SalesOrderDetail”)

select contact).FirstOrDefault();

 

  1. Contact customer = (from contact in context.Contact.Include

(“SalesOrderHeader”)

select contact).FirstOrDefault();

 

Correct Answer: A

 

 

QUESTION 209

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

 

01 public static SqlDataReader GetDataReader(string sql)

02 {

03 SqlDataReader dr = null;

04 …

05 return dr;

06 }

 

You need to ensure that the following requirements are met:

 

  • The SqlDataReader returned by the GetDataReader method can be used to retreive rows from the database.

  • SQL connections opened within the GetDataReader method will close when the SqlDataReader is closed.

 

Which code segment should you insert at the line 04?

 

  1. using(SqlConnection cnn = new SqlConnection(strCnn))

{

try

{

SqlCommand cmd = new SqlCommand(sql, cnn);

cnn.Open();

dr = cmd.ExecuteReader();

}

catch

{

throw;

}

}

 

  1. SqlConnection cnn = new SqlConnection(strCnn);

SqlCommand cmd = new SqlCommand(sql, cnn);

cnn.Open();

{

try

{

dr = cmd.ExecuteReader();

}

finally

{

cnn.Close();

}

}

 

  1. SqlConnection cnn = new SqlConnection(strCnn);

SqlCommand cmd = new SqlCommand(sql, cnn);

cnn.Open();

{

try

{

dr = cmd.ExecuteReader();

cnn.Close();

}

catch

{

throw;

}

}

 

  1. SqlConnection cnn = new SqlConnection(strCnn);

SqlCommand cmd = new SqlCommand(sql, cnn);

cnn.Open();

{

try

{

dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

}

catch

{

cnn.Close();

throw;

}

}

 

Correct Answer: D

 

 

QUESTION 210

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 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.

 

70-516-demo-30

 

You need to calculate the total bonus for all sales people in each sales territory. Which code segment should you use?

 

  1. from person in model.SalesPersons

group person by person.SalesTerritory

into territoryByPerson

select new

{

SalesTerritory = territoryByPerson.Key,

TotalBonus = territoryByPerson.Sum(person => person.Bonus)

};

 

  1. from territory in model.SalesTerritories

group territory by territory.SalesPerson

into personByTerritories

select new

{

SalesTerritory = personByTerritories.Key,

TotalBonus = personByTerritories.Key.Sum(person => person.Bonus)

};

 

 

  1. model.SalesPersons

.GroupBy(person => person.SalesTerritory)

.SelectMany(group => group.Key.SalesPersons)

.Sum(person => person.Bonus);

 

  1. model.SalesTerritories

.GroupBy(territory => territory.SalesPersons)

.SelectMany(group => group.Key)

.Sum(person => person.Bonus);

 

Correct Answer: A

 

Instant Access to Download Latest Complete Collection of Microsoft MCTS 70-516 Real Exam

Try Microsoft MCTS 70-516 Free Demo

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.