Appendix B. Data access fundamentals

 

Throughout this book, we’ve used Entity Framework to access data stored in a database. Although it’s recommended, Entity Framework isn’t the only choice for retrieving data. A good alternative is to use ADO.NET. Entity Framework itself leverages this component. ADO.NET is easy to use, but you have to manually handle the connection to the database, the command to execute queries, and the transaction to execute multiple update commands. Finally, data isn’t returned as objects but as a generic-purpose container. All these features make ADO.NET simple but extremely code intensive. That’s why Entity Framework is the recommended approach.

Another alternative for managing data is to use XML. Although you can’t use XML as a database in medium to big real-world applications, it’s still perfectly valid for other purposes. It’s a great format for data exchange through messages or files and is perfectly suitable for storing configuration information (the web.config file is an XML file) or small pieces of data. For these reasons, it’s important for you to know about XML.

Let’s start this appendix by discussing how to use ADO.NET to retrieve and update data. As usual, we’re going to use the Northwind database so that you can compare the code in this chapter to the one in chapter 2. The code examples are similar, but you’ll discover how much more code is required with ADO.NET.

B.1. Using ADO.NET to access data

B.2. Reading and writing XML

B.3. Summary