nerdexam
Microsoft

70-516 · Question #72

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to develop an application that uses the Entity Framework. Entity types in the model are generated by the Entity Data Model…

The correct answer is A. var formatter = new XmlSerializer(typeof(Contact), new Type[]. public XmlSerializer(Type type, Type[] extraTypes) Initializes a new instance of the System.Xml.Serialization.XmlSerializer class that can serialize objects of the specified type into XML documents, and deserialize XML documents into object of a specified type. If a property or…

Consuming and Exposing Data

Question

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to develop an application that uses the Entity Framework. Entity types in the model are generated by the Entity Data Model generator tool (EdmGen.exe). You write the following code. (Line numbers are included for reference only.) 01 MemoryStream stream = new MemoryStream(); 02 var query = context.Contacts.Include(“SalesOrderHeaders.SalesOrderDetails”); 03 var contact = query.Where(“it.LastName = @lastname”, new ObjectParameter(“lastname”, lastName)).First(); 04 .... You need to serialize the contact and all of its related objects to the MemoryStream so that the contact can be deserialized back into the model. Which code segment should you insert at line 04?

Options

  • Avar formatter = new XmlSerializer(typeof(Contact), new Type[]
  • Bvar formatter = new XmlSerializer(typeof(Contact));
  • Cvar formatter = new BinaryFormatter();
  • Dvar formatter = new SoapFormatter();

How the community answered

(17 responses)
  • A
    76% (13)
  • B
    6% (1)
  • C
    12% (2)
  • D
    6% (1)

Explanation

public XmlSerializer(Type type, Type[] extraTypes) Initializes a new instance of the System.Xml.Serialization.XmlSerializer class that can serialize objects of the specified type into XML documents, and deserialize XML documents into object of a specified type. If a property or field returns an array, the extraTypes parameter specifies objects that can be inserted into the array. The type of the object that this System.Xml.Serialization.XmlSerializer can serialize.extraTypes: A System.Type array of additional object types to serialize. XmlSerializer Constructor (Type, Type[])

Topics

#Entity Framework#XmlSerializer#entity serialization#known types

Community Discussion

No community discussion yet for this question.

Full 70-516 Practice