你的位置:首页 > ASP.net教程

[ASP.net教程]创建实体数据模型(EF基础系列5)


现在我要来为上面一节末尾给出的数据库(SchoolDB)创建实体数据模型;

SchoolDB数据库的脚本我已经写好了,如下:

USE masterGO IF EXISTS(SELECT * FROM sys.sysdatabases WHERE name='SchoolDB')DROP DATABASE SchoolDB;GO CREATE DATABASE SchoolDBGO USE SchoolDB;GO 
--创建Standard表IF EXISTS (SELECT * FROM sysobjects WHERE name='Standard')DROP TABLE [Standard];GO
CREATE TABLE [Standard](StandardID INT PRIMARY KEY ,StandardName NVARCHAR(50),[Description] NVARCHAR(250)); GO
--创建Student表IF EXISTS (SELECT * FROM sysobjects WHERE name='Student')DROP TABLE Student;GO CREATE TABLE Student(StudentID INT PRIMARY KEY,StudentName NVARCHAR(100) NOT NULL,StandardID INT REFERENCES [Standard](StandardID),[RowVersion] NVARCHAR(50));GO --创建StudentAddress表IF EXISTS (SELECT * FROM sysobjects WHERE name='StudentAddress')DROP TABLE StudentAddress;GO CREATE TABLE StudentAddress(StudentID INT PRIMARY KEY,Address1 NVARCHAR(100) ,Address2 NVARCHAR(100), City NVARCHAR(100),[State] NVARCHAR(100));GO --创建Teacher表IF EXISTS (SELECT * FROM sysobjects WHERE name='Teacher')DROP TABLE Teacher;GO CREATE TABLE Teacher(TeacherID INT PRIMARY KEY ,TeacherName NVARCHAR(50),StandardID INT REFERENCES [Standard](StandardID),TeacherType NVARCHAR (100));GO --创建Course表IF EXISTS (SELECT * FROM sysobjects WHERE name='Course')DROP TABLE Course;GO CREATE TABLE Course(CourseID INT PRIMARY KEY ,CourseName NVARCHAR(50),Location NVARCHAR(500),TeacherID INT REFERENCES dbo.Teacher(TeacherID));GO --创建StudentCourse表IF EXISTS (SELECT * FROM sysobjects WHERE name='StudentCourse')DROP TABLE StudentCourse;GO CREATE TABLE StudentCourse(StudentID INT ,CourseID INT ,CONSTRAINT StudentID_CourseID PRIMARY KEY(StudentID,CourseID));GO

 

首先我们打开上面一节创建的项目,选中“项目名称”,右键选择”属性“,我们要确保使用的.NET framework版本是4.5;

接下来,就是创建实体数据模型了:选中项目名称:

现在我们以