In Chapter 8, we saw the ExecuteXmlReader method exposed by the SqlCommand class in the SQL Server–managed provider. The ExecuteXmlReader method executes a command against the database and returns an XML reader if the output of the command can be expressed as a well-formed XML document or fragment. Let’s see what’s needed to transform that output into an instance of a class. The following code is at the heart of the example. You call into a method, the method executes an SQL XML command, the data flows into the serializer, and an instance of a particular class is returned.
Employee emp = LoadEmployeeData(empID);
The following code shows the body of the LoadEmployeeData method:
private Employee LoadEmployeeData(int empID) ...