nerdexam
Microsoft

70-516 · Question #40

70-516 Question #40: Real Exam Question with Answer & Explanation

The correct answer is A. DbDataRecord nestedRecord = rdr["EmailPhoneComplexProperty"]. How to: Execute a Query that Returns Complex Types using (EntityConnection conn = new EntityConnection(ConfigurationManager.ConnectionStrings ["StoreConnection"].ConnectionString)) using (EntityCommand comm = conn.CreateCommand()) { // Here StoreConnection-ObjectContext name, Cus

Question

You have been assigned the task of writing code that executes an Entity SQL query that returns entity type objects that contain a property of a complex type. (Line numbers are included for reference only.) 01 using (EntityCommand cmd = conn.CreateCommand()) 02 { 03 cmd.CommandText = esqlQuery; 04 EntityParameter param = new EntityParameter(); 05 param.ParameterName = "id"; 06 param.Value = 3; 07 cmd.Parameters.Add(param); 08 using (EntityDataReader rdr = cmd.ExecuteReader(CommandBehavior.SequentialAccess)) 09 { 10 while (rdr.Read()) 11 { 12 ... 13 Console.WriteLine("Email and Phone Info:"); 14 for (int i = 0; i < nestedRecord.FieldCount; i++) 15 { 16 Console.WriteLine(" " + nestedRecord.GetName(i) + ": " + nestedRecord.GetValue(i)); 17 } 18 } 19 } 20 } Which code segment should you insert at line 12?

Options

  • ADbDataRecord nestedRecord = rdr["EmailPhoneComplexProperty"]
  • BDbDataRecord nestedRecord = rdr["EmailPhoneComplexProperty"]
  • CDataSet nestedRecord = rdr["EmailPhoneComplexProperty"]
  • DComplexDataRecord nestedRecord = rdr["EmailPhoneComplexProperty"]

Explanation

How to: Execute a Query that Returns Complex Types using (EntityConnection conn = new EntityConnection(ConfigurationManager.ConnectionStrings ["StoreConnection"].ConnectionString)) using (EntityCommand comm = conn.CreateCommand()) { // Here StoreConnection-ObjectContext name, Customers-correct DataSet name comm.CommandText = "Select Customers.CustomerID, Customers.Name, Customers.Address from StoreConnection.Customers where Customers.CustomerID=@qqqCustomerID"; EntityParameter param = new EntityParameter("qqqCustomerID", DbType.Int32); param.Value = 1; comm.Parameters.Add(param); var reader = comm.ExecuteReader(CommandBehavior.SequentialAccess); while (reader.Read()) DbDataRecord record = reader["Address"] as DbDataRecord; for (int i = 0; i < record.FieldCount; i++) name.Text += "<br/>" + record.GetName(i) + " : " + record.GetValue(i).ToString(); }

Community Discussion

No community discussion yet for this question.

Full 70-516 Practice