一. 什么是数据访问层
在wingtip项目中,数据访问层是对以下三者的总称:
1. product类等数据相关的类(class)
2. 数据库和存储类成员的数据表(database)
3. 上述二者的交互操作。
product类:
1 using System.ComponentModel.DataAnnotations; 2 3 namespace WingtipToys.Models 4 { 5 public class Product 6 { 7 [ScaffoldColumn(false)] 8 public int ProductID { get; set; } 9 10 [Required, StringLength(100), Display(Name = "Name")] 11 public string ProductName { get; set; } 12 13 [Required, StringLength(10000), Display(Name = "Product Description"), DataType(DataType.MultilineText)] 14 public string Description { get; set; } 15 16 public string ImagePath { get; set; } 17 18 [Display(Name = "Price")] 19 public double? UnitPrice { get; set; } 20 21 public int? CategoryID { get; set; } 22 23 public virtual Category Category { get; set; } 24 } 25 }
database(T-SQL):
1 CREATE TABLE [dbo].[Products] ( 2 [ProductID] INT IDENTITY (1, 1) NOT NULL, 3 [ProductName] NVARCHAR (100) NOT NULL, 4 [Description] NVARCHAR (MAX) NOT NULL, 5 [ImagePath] NVARCHAR (MAX) NULL, 6 [UnitPrice] FLOAT (53) NULL, 7 [CategoryID] INT NULL, 8 CONSTRAINT [PK_dbo.Products] PRIMARY KEY CLUSTERED ([ProductID] ASC), 9 CONSTRAINT [FK_dbo.Products_dbo.Categories_CategoryID] FOREIGN KEY ([CategoryID]) REFERENCES [dbo].[Categories] ([CategoryID]) 10 ); 11 12 13 GO 14 CREATE NONCLUSTERED INDEX [IX_CategoryID] 15 ON [dbo].[Products]([CategoryID] ASC);
原文地址:https://www.cnblogs.com/codingcz/p/9501574.html
时间: 2024-11-08 07:27:16