ASP.NET Data Access - Recommended Resources
This topic provides links to documentation resources about how to access data in ASP.NET web applications, primarily by using the Entity Framework and SQL Server.
Last updated 4/3/2014
The topic contains the following sections:
- Getting Started with Data Access in ASP.NET
- Using Entity Framework Code First
- Using Entity Framework Code First Migrations
- Using Entity Framework Database First or Model First (the EF Designer)
- Loading Related data in Entity Framework (Lazy Loading, Eager Loading, and Explicit Loading)
- Optimizing Entity Framework Performance
- Handling Concurrency in an Entity Framework Application
- Books about the Entity Framework
- Additional Entity Framework resources
- Working with NoSQL Database Management Systems
- Using LINQ queries in ASP.NET Applications
- Using Dynamic Data scaffolding
- Securing Data Access
- Optimizing Data Access Performance
- Deploying a Database
- Accessing Data through a Web Service
- Additional Resources
Getting Started with Data Access in ASP.NET
- Data Storage Options (Building Real-World Cloud Apps with Windows Azure). Chapter of an e-book about developing for the cloud. Introduces NoSQL databases as an alternative that many developers familiar with relational databases tend to overlook. Presents guidelines on what to think about when choosing relational or NoSQL, or choosing a particular platform.
- ASP.NET Data Access Options (MSDN). An introduction to data access options for relational databases for ASP.NET and guidance on how to choose platforms and access methods that are appropriate for your scenario.
- Relational database. Wikipedia). If you haven't worked with relational databases, see this page for an introduction to relational database terminology and concepts. For an introduction to SQL Server in particular see Working with SQL Server databases later in this topic.
Using the Entity Framework
- Entity Framework Development Approaches (MSDN). Guidance on how to choose an Entity Framework development approach Database First, Model First, or Code First.
Using Entity Framework Code First
The following tutorials offer downloadable sample applications:
- Getting Started with EF 6 using MVC 5. Covers a wide range of Entity Framework Code First scenarios, including Migrations and EF 6 features such as connection resiliency, command interception, and async. This is an updated version of the EF 5 / MVC 4 series. The earlier series includes a tutorial on the repository and unit-of-work patterns that is not included in the new series.
- Introduction to ASP.NET MVC 5. Covers a narrower range of Entity Framework Code First scenarios but does a more comprehensive job of introducing MVC features.
- Model Binding and Web Forms. Uses Code First in a Web Forms application.
- Getting Started with ASP.NET 4.5 Web Forms. An introduction to Web Forms with some coverage of Code First. Uses Model Binding.
- MVC Music Store. Uses Code First in an e-commerce MVC 3 application that also implements membership and authorization. The MVC version and ASP.NET membership (authentication and authorization) system used here are outdated; for more up-to-date information on ASP.NET membership, see https://asp.net/identity.
- Entity Framework - Code First to an Existing Database. MSDN. Video and walkthrough that shows how to use Code First with an existing database.
- Data Developer Center - Entity Framework. MSDN. For a guide to Entity Framework documentation that has been created and maintained by the Entity Framework team, see the Get Started link.
Using Entity Framework Code First Migrations
Most of the Code First tutorials listed above cover migrations. See also the following resources.
- ASP.NET Web Deployment using Visual Studio. 2-part tutorial series that shows how to use Code First Migrations to deploy a database.
- Deploy a Secure ASP.NET MVC 5 app with Membership, OAuth, and SQL Database to a Windows Azure Web Site. Microsoft Azure). How to use migrations to deploy membership and application data to Azure.
- Web Deployment Overview for Visual Studio and ASP.NET. See the Configuring Database Deployment in Visual Studio section for an explanation of how Code First Migrations is integrated into Visual Studio web deployment features.
- Data Developer Center - Code First Migrations (MSDN). The Entity Framework team's Migrations documentation.
- Migrations Screencast Series. EF blog). Three videos on advanced topics in Code First Migrations.
- Code First Migrations With ASP.NET Web Pages Sites. Mikesdotnetting blog). Shows how to use Code First migrations with an ASP.NET Web Pages site by putting the data context in a Visual Studio class library project.
Using Entity Framework Database First or Model First (the EF Designer)
- Getting Started with Entity Framework 6 Database First using MVC 5. Run a script in Server Explorer to create a database, and then use the Entity Framework designer to create the data model. Shows how to create simple CRUD web pages, and for other data handling functions you can follow one of the Code First tutorials since all EF workflows use the same DbContext API.
The following resources are older. They are useful if you want to use version 4.0 of the Entity Framework, and you want to use a data source control for data binding in a Web Forms application.
- Getting Started with the Entity Framework 4.0. Shows how to use the EntityDataSource control.
- Continuing with the Entity Framework(Shows how to use the ObjectDataSource Control. Includes a tutorial on concurrency handling, a tutorial on EF performance, and a tutorial on what's new in EF 4.0.
Handling related data in Entity Framework (Lazy Loading, Eager Loading, and Explicit Loading)
- Reading Related Data with the Entity Framework in an ASP.NET MVC Application. Code First, MVC sample application. The methods shown apply also to Web Forms model binding and the Database First workflow.
- Data Developer Center - Loading Related Entities (MSDN). The Entity Framework team's documentation about loading related data.
Optimizing Entity Framework performance
- Advanced Entity Framework Scenarios for an ASP.NET Application. Shows how to execute your own SQL statements or call your own stored procedures, how to disable change detection, and how to disable validation when saving changes.
- Performance Considerations for Entity Framework 5 (MSDN).
- Performance Considerations (Entity Framework) (MSDN).
- Maximizing Performance with the Entity Framework in an ASP.NET Web Application. Applies to Entity Framework 4.0.
- See also Optimizing ASP.NET data access later in this topic.
Handling Concurrency in an Entity Framework Application
- Handling Concurrency with the Entity Framework in an ASP.NET MVC Application. Code First, DbContext API, using an MVC sample application.
- Data Developer Center – Optimistic Concurrency Patterns (MSDN). The Entity Framework team's concurrency documentation.
- Handling Concurrency with the Entity Framework in an ASP.NET Web Application. Applies to Entity Framework 4.0. Database First, ObjectContext API, using a Web Forms sample application.
Books about the Entity Framework
- Programming Entity Framework: DbContext by Julie Lerman and Rowan Miller.
- Programming Entity Framework: Code First by Julie Lerman and Rowan Miller.
Both of these books are up-to-date with current recommended techniques. They provide a more comprehensive yet easy-to-follow introduction to the Entity Framework than anything available on the Internet. Another book, Programming Entity Framework by Julie Lerman, is larger and more comprehensive but it is older and many of the techniques it covers are no longer the recommended way to use the Entity Framework. See also the list of books recommended by the Entity Framework team at Data Developer Center - Books on the MSDN site.
Other Entity Framework Resources
- Entity Framework (ADO.NET) team blog. One of the best resources for the most current information and announcements of new enhancements. For other EF-related blogs, see the Blogroll at Get Started with Entity Framework.
- MSDN Magazine. See the Data Points column, which is frequently about topics related to the Entity Framework.
Data Binding in ASP.NET Web Forms Applications
Using Web Forms Model Binding
- Model Binding and Web Forms. Tutorial series using EF Code First.
- Web Forms Model Binding Part 1: Selecting Data (Scott Guthrie's blog). In these older blog posts, the property that is currently named ItemType was named ModelType, but otherwise the information they contain is valid.
- Web Forms Model Binding Part 2: Filtering Data (Scott Guthrie's blog).
- Web Forms Model Binding Part 3: Updating and Validation (Scott Guthrie's blog).
- ASP.NET 4.5 Web Forms Model Binding. (video).
- Model Binding Part 1 - Selecting Data (video).
- Model Binding Part 2 - Filtering (video).
- Getting Started with ASP.NET 4.5 Web Forms - Display Data Items and Details.
Using Web Forms Data Source Controls
- Data Source Web Server Controls (MSDN).
- Announcing the release of Dynamic Data provider and EntityDataSource control for Entity Framework 6 (Microsoft Web Development blog).
Using Web Forms Data-Bound Controls and Data-Binding Expressions
- Model Binding and Web Forms. Tutorial series that uses EF Code First.
- Getting Started with ASP.NET 4.5 Web Forms - Display Data Items and Details.
- Strongly Typed Data Controls (Scott Guthrie's blog).
- Strongly Typed Data Controls (video).
- ASP.NET 4.5 Web Forms Strong Typed Data Controls (video).
- Data-Bound Web Server Controls (MSDN).
- Data-Binding Expressions Overview (MSDN). This page only covers Eval and Bind; it has not been updated to include Item and BindItem.
Working with SQL Server Databases
- SQL Server Database Features (MSDN). For a general introduction to a wide variety of SQL Server topics, see the entries under this one in the TOC.
- SQL Server Editions (MSDN). A summary of the available SQL Server editions, with links to more information about each one.)
- SQL Server Connection Strings for ASP.NET Web Applications (MSDN).
- Using SQL Server Compact for ASP.NET Web Applications (MSDN).
- Microsoft SQL Server: Database Product Samples. Sample AdventureWorks databases.
- Installing Sample Databases. In addition to the methods shown here, you can also download one of the sample .mdf files to the App_Data folder of a web project, convert the database to LocalDB, and create a LocalDB connection string. For information about how to do that, see How to: Upgrade to LocalDB.
See also the following sections on working with SQL Server Express and LocalDB, and choosing between SQL Server and SQL Database.
Working with SQL Server Express LocalDB Databases
- SQL Server Express 2012 LocalDB (MSDN). The official MSDN introduction to LocalDB.
- SQL Server Connection Strings for ASP.NET Web Applications (MSDN).
- How to: Upgrade to LocalDB (MSDN). How to migrate an .mdf file from an earlier version of SQL Server Express to LocalDB. You also have to go through this process if you download one of the SQL Server 2012 sample databases.
- Introducing LocalDB, an improved SQL Express (SQL Server Express blog). Has more background on why LocalDB was created than is included in MSDN.
- LocalDB: Where is My Database? (SQL Server Express blog). Information about where LocalDB database files are created.
- Using LocalDB with Full IIS, Part 1: User Profile (SQL Server Express blog). LocalDB is not designed to work with IIS. This series of blog posts explains the issues and some workarounds.
Working with SQL Server Express Databases
- SQL Server Connection Strings for ASP.NET Web Applications (MSDN). If you use the AttachDBFileName connection string setting with SQL Server Express, see especially the User Instance section of this page.
- How to take ownership of your local SQL Server Express 2008 (SQL Server Express blog). A common problem is not being able to work with SQL Server Express databases because you're not an administrator on the SQL Server Express instance. By default, only the person who installed SQL Server Express is an administrator. This blog explains how to make yourself a SQL Server Express administrator if you're an administrator on the computer.
- Can my ASP.NET web application use a SQL Server Express database in production? (MSDN).
Working with Windows Azure SQL Database
- Deploy a Secure ASP.NET MVC app with Membership, OAuth, and SQL Database to a Windows Azure Web Site (Microsoft Azure site).
- SQL Databases (Microsoft Azure site). Getting started tutorials and how-to guides.
- Windows Azure SQL Database (MSDN). The top-level node of the table of contents for SQL Database in MSDN.
- Windows Azure SQL Database TechNet Wiki Articles Index (Microsoft TechNet site).
- Transient Fault Handling Application Block. A framework that enables you to handle transient network faults and connection errors that result from throttling. Available in a NuGet package: Enterprise Library 5.0 - Transient Fault Handling Application Block.
- Getting Started with SQL Database and Entity Framework (MSDN).
- Windows Azure Training Kit (Microsoft Download Center). Includes hands-on labs for SQL Database.
- Windows Azure SQL Database Community Forum.
- Moving to Windows Azure SQL Database (MSDN). One chapter of a comprehensive end-to-end scenario by the Microsoft Patterns and Practices team. Covers why you might want to migrate and how to migrate from SQL Server to SQL Database.
- Migrating SQL Server Databases to Windows Azure SQL Database (MSDN).
- SQL Database Migration Wizard. An open source tool for migrating databases to and from SQL Database.
Choosing between SQL Server and Windows Azure SQL Database
- Compare SQL Server with Windows Azure SQL Database (Microsoft TechNet site).
- Data Migration to Windows Azure SQL Database: Tools and Techniques (MSDN). Includes sections that compare SQL Server to SQL Database and provide guidance on when to migrate from SQL Server to SQL Database.
- Windows Azure SQL Database Delivery Guide (Microsoft TechNet site).
- SQL Server Feature Limitations (Windows Azure SQL Database) (MSDN).
- Windows Azure Table Storage and Windows Azure SQL Database - Compared and Contrasted (MSDN). For an application that you deploy to Windows Azure, Windows Azure Table storage might be an alternative to Windows Azure SQL Database. This topic helps you decide between these alternatives.
- Windows Azure SQL Database (MSDN).
- Guidelines and Limitations (Windows Azure SQL Database)
Working with NoSQL Database Management Systems
- Windows Azure Data Services (Microsoft Azure site). See the Table Service feature guide and the Big Data section of the page.
- ASP.NET Multi-Tier Application Using Storage Tables, Queues, and Blobs (Microsoft Azure site). End-to-end tutorial with downloadable sample application that uses Windows Azure storage NoSQL tables.
Using LINQ Queries in ASP.NET Applications
- ASP.NET Data Access Options (MSDN). Includes an introduction to LINQ.
- LINQ Training Videos (Joe Stagner's blog).
- ASP.NET Forum thread with links to dynamic LINQ resources.
Using Dynamic Data Scaffolding
- Dynamic Data Project Templates (MSDN). Guidance on when to use Dynamic Data projects.
- ASP.NET Dynamic Data (MSDN).
Securing Data Access
- Securing Data Access in ASP.NET (MSDN).
- Security Considerations (Entity Framework) (MSDN).
- How To: Secure Connection Strings when Using Data Source Controls (MSDN).
Optimizing Data Access Performance
- ASP.NET Performance Overview (MSDN).
- ASP.NET Caching (MSDN).
- Improving ASP.NET Performance (MSDN). There is a "Retired Content" warning at the top of this page, but most of the information is still relevant and there is no comparable updated resource.
- Improving SQL Server Performance (MSDN). Same comment as the previous link.
See also Optimizing Entity Framework performance earlier in this topic.
Deploying a Database
Accessing Data through a Web Service
- Accessing Data through a Web Service (MSDN). Guidance on when to use Web API versus WCF.
- Getting Started with ASP.NET Web API.
- WCF Data Services (MSDN).
- ASP.NET Data Access FAQ (MSDN).
- ASP.NET Web Forms Tutorials - Data. Most of these tutorials are relatively old; make sure you read ASP.NET Data Access Options and Data Storage Options (Building Real-World Cloud Apps with Windows Azure) first so that you don't get too far into a data access method that isn't right for your scenario.
- ASP.NET MVC Content Map.
- ASP.NET Web Pages Tutorials - Data.
- Accessing Data in Visual Studio (MSDN). Provides a list of links similar to this content map but with a focus on Visual Studio rather than ASP.NET.