一、先建数据库。
打开,SQL Server Management 新建数据库Employee
并新建表
/****** Object: Table [dbo].[t_Employee] Script Date: 2016/8/5 下午 07:24:45 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[t_Employee]( [F_Id] [int] IDENTITY(1,1) NOT NULL, [F_FirstName] [nvarchar](50) NOT NULL, [F_LastName] [nvarchar](50) NOT NULL, [F_MiddleName] [nvarchar](50) NULL, [F_Address] [nvarchar](300) NULL, [F_Salary] [decimal](18, 2) NULL, [F_Email] [nvarchar](50) NULL, CONSTRAINT [PK_t_Employee] PRIMARY KEY CLUSTERED ( [F_Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO
二、新建项目:DatabaseFirst,(具体方法见第一篇)
三、在Models文件夹新建项:
完成之后,VS为我们生成以下文件:
HRModels.Context.cs对应DbContext类,
t_Employee对应Model类。
四、增删查改的实现参照第一节。
时间: 2024-10-14 10:16:34