O'Reilly logo

Applied XML Programming for Microsoft® .NET by Dino Esposito

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mapping SQL Server Data to Classes

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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required