Part 2: Data Access Layer 数据访问层
Tailspin Spyworks demonstrates how extraordinarily simple it is to create powerful, scalable applications for the .NET platform. It shows off how to use the great new features in ASP.NET 4 to build an online store, including shopping, checkout, and administration.
通过Tailspin Spyworks 演示在.NET平台创建功能强大,结构良好的应用程序有多么简单。演示如何使用ASP.NET 4的新特性创建一个包含购物、结算和管理功能的在线网店。
This tutorial series details all of the steps taken to build the Tailspin Spyworks sample application. Part 2 covers adding the data access layer.
本系列指南对构建案例程序的每一步做了详细的解释。第二部分讲述添加数据访问层。
添加数据访问层
Our ecommerce application will depend on two databases.
此电子商务程序将需要两个数据库。
For customer information we'll use the standard ASP.NET Membership database. For our shopping cart and product catalog we'll implement a SQL Express database as follows.
我们将使用standard ASP.NET Membership database。购物车和产品数据将创建一个新的数据库来保存。
Having created the database (Commerce.mdf) in the application's App_Data folder we can proceed to create our Data Access Layer using the .NET Entity Framework.
在App_Data文件夹创建数据库(Commerce.mdf)之后,我们使用.NET EntityFramework创建数据访问层。(提示:也可在SQL Server标准版中直接创建此数据库)。
We'll create a folder named "Data_Access" and them right click on that folder and select "Add New Item".
创建名为“Data_Access”文件夹,然后在其上右键选择“添加新项”。
In the "Installed Templates" item and then select "ADO.NET Entity Data Model" enter EDM_Commerce.edmx as the name and click the "Add" button.
在对话框中选择“ADO.NET Entity Data Model",命名为EDM_Commerce.edmx,然后点击”添加“按钮。
Choose "Generate from Database".
选择”从数据库生成“。
Save and build.
保存并生成。
Now we are ready to add our first feature – a product category menu.
我们由此准备好添加新功能-产品目录。