码迷,mamicode.com
首页 > 其他好文 > 详细

创建实体数据模型(EF基础系列5)

时间:2015-09-12 16:01:14      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:

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

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

USE master
GO 
IF EXISTS(SELECT * FROM sys.sysdatabases WHERE name=SchoolDB)
DROP DATABASE SchoolDB;
GO 
CREATE DATABASE SchoolDB
GO 
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;

技术分享

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

技术分享

技术分享

技术分享

技术分享

技术分享

现在我们以XML编译器的方式打开EDMX文件看看:

技术分享

创建实体数据模型(EF基础系列5)

标签:

原文地址:http://www.cnblogs.com/caofangsheng/p/4803042.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!