N-Tier Data Applications Overview
N-tier data applications are data applications that are separated into multiple tiers. Also called "distributed applications" and "multitier applications," n-tier applications separate processing into discrete tiers that are distributed between the client and the server. When you develop applications that access data, you should have a clear separation between the various tiers that make up the application.
A typical n-tier application includes a presentation tier, a middle tier, and a data tier. The easiest way to separate the various tiers in an n-tier application is to create discrete projects for each tier that you want to include in your application. For example, the presentation tier might be a Windows Forms application, whereas the data access logic might be a class library located in the middle tier. Additionally, the presentation layer might communicate with the data access logic in the middle tier through a service such as a service. Separating application components into separate tiers increases the maintainability and scalability of the application. It does this by enabling easier adoption of new technologies that can be applied to a single tier without the requirement to redesign the whole solution. In addition, n-tier applications typically store sensitive information in the middle-tier, which maintains isolation from the presentation tier.
Visual Studio contains several features to help developers create n-tier applications:
The Dataset Designer provides a DataSet Project property that enables you to separate the dataset (data entity layer) and TableAdapters (data access layer) into discrete projects.
The Object Relational Designer (O/R Designer) provides settings to generate the DataContext and data classes into separate namespaces. This enables logical separation of the data access and data entity tiers.
LINQ to SQL provides the Attach method that enables you to bring together the DataContext from different tiers in an application. For more information, see N-Tier and Remote Applications with LINQ to SQL.
The Configure Data Synchronization dialog box, which helps you configure synchronization between a remote database and Local Database Cache, provides an advanced configuration option. This option enables you to set the server and client to separate projects. For more information, see Walkthrough: Adding a Local Database Cache to an N-Tier Application.
For a related video demonstration, see Video How to: Creating an N-Tier Data Application.
The presentation tier is the tier in which users interact with an application. It often contains additional application logic also. Typical presentation tier components include the following:
Object representations of data, such as LINQ to SQL entity classes for use in the presentation tier.
Local databases, such as a Local Database Cache that can be synchronized with the server in the data tier by using Microsoft Synchronization Services for ADO.NET in Occasionally Connected Applications (Local Database Caching).
The following illustration shows features and technologies that are available in Visual Studio and where they might fit in to the presentation tier of an n-tier application.
The presentation tier typically accesses the middle tier by using a service reference (for example, a Windows Communication Foundation Services and WCF Data Services in Visual Studio application). The presentation tier does not directly access the data tier. The presentation tier communicates with the data tier by way of the data access component in the middle tier.
The middle tier is the layer that the presentation tier and the data tier use to communicate with each other. Typical middle tier components include the following:
Business logic, such as business rules and data validation.
Data access components and logic, such as the following:
The following illustration shows features and technologies that are available in Visual Studio and where they might fit in to the middle tier of an n-tier application.
The middle tier typically connects to the data tier by using a data connection. This data connection is typically stored in the data access component.
The data tier is basically the server that stores an application's data (for example, a server running SQL Server).
The following illustration shows features and technologies that are available in Visual Studio and where they might fit in to the data tier of an n-tier application.
The data tier cannot be accessed directly from the client in the presentation tier. Instead, the data access component in the middle tier is used for communication between the presentation and data tiers.
The following topics provide information about working with n-tier applications: