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 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?
A.
int FldIdx = 0;
EntityKey key = record.GetValue(FldIdx) as EntityKey;
foreach (EntityKeyMember keyMember in key.EntityKeyValues)
{
return keyMember.Key + ” : ” + keyMember.Value;
}
B.
IExtendedDataRecord record = rdr[“EmailPhone”]as IExtendedDataRecord;
int FldIdx = 0;
return record.GetValue(FldIdx);
C.
DbDataRecord nestedRecord = rdr[“EmailPhoneComplexProperty”] as DbDataRecord; return
nestedRecord;
D.
int fieldCount = rdr[“EmailPhone”].DataRecordInfo.FieldMetadata.Count;
for (int FldIdx = 0; FldIdx < fieldCount; FldIdx++)
{
rdr.GetName(FldIdx); if (rdr.IsDBNull(FldIdx) == false)
{
return rdr[“EmailPhone”].GetValue(FldIdx).ToString();
}
}