现在我要来为上面一节末尾给出的数据库(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(),
[Description] NVARCHAR()
);

GO 

--创建Student表
IF EXISTS (SELECT * FROM sysobjects WHERE name='Student')
DROP TABLE Student;
GO
CREATE TABLE  Student
(
StudentID INT PRIMARY KEY,
StudentName NVARCHAR() NOT NULL,
StandardID INT  REFERENCES [Standard](StandardID),
[RowVersion] NVARCHAR()

);

GO 

--创建StudentAddress表
IF EXISTS (SELECT * FROM sysobjects WHERE name='StudentAddress')
DROP TABLE StudentAddress;
GO
CREATE TABLE  StudentAddress
(
StudentID INT PRIMARY KEY,
Address1 NVARCHAR() ,
Address2 NVARCHAR(),
City NVARCHAR(),
[State] NVARCHAR(),
CONSTRAINT StudentID_FK FOREIGN KEY(StudentID) REFERENCES dbo.Student(StudentID)
);

GO 

--创建Teacher表
IF EXISTS (SELECT * FROM sysobjects WHERE name='Teacher')
DROP TABLE Teacher;
GO
CREATE TABLE  Teacher
(
TeacherID INT PRIMARY KEY ,
TeacherName NVARCHAR(),
StandardID INT  REFERENCES [Standard](StandardID),
TeacherType NVARCHAR ()

);
GO 

--创建Course表
IF EXISTS (SELECT * FROM sysobjects WHERE name='Course')
DROP TABLE Course;
GO
CREATE TABLE  Course
(
CourseID INT PRIMARY KEY ,
CourseName NVARCHAR(),
Location NVARCHAR(),
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  REFERENCES Student(StudentID),
CourseID INT  REFERENCES dbo.Course(CourseID),
CONSTRAINT StudentID_CourseID PRIMARY KEY(StudentID,CourseID),

);

GO 

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

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

Note:

Pluralize or singularize generated object names checkbox singularizes an entityset name, if the table name in the database is plural. For example, if SchoolDB has Students table name then entityset would be singular Student. Similarly, relationships between the models will be pluralized if the table has one-to-many or many-to-many relationship with other tables. For example, Student has many-to-many relationship with Course table so Student entity set will have plural property name 'Courses' for the collection of courses.

The second checkbox, Include foreign key columns in the model, includes foreign key property explicitly to represent the foreign key. For example, Student table has one-to-many relationship with Standard table. So every student is associated with only one standard. To represent this in the model, Student entityset includes StandardId property with Standard navigation property. If this checkbox is unchecked then it will only include the Standard property, but not the StandardId in the Student entityset.

The third checkbox, Import selected stored procedures and functions into entity model, automatically creates Function Imports for the stored procedures and functions. You don't need to manually import this, as was necessary prior to Entity Framework 5.0.

7. After clicking on 'Finish', a School.edmx file will be added into your project.

Open EDM designer by double clicking on School.edmx. This displays all the entities for selected tables and the relationships between them as shown below:

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

这篇没什么用,纯属扯淡的。可以略过。。。

创建实体数据模型【Create Entity Data Model】(EF基础系列5)的更多相关文章

  1. EntityFramework 学习 一 创建实体数据模型 Create Entity Data Model

    1.用vs2012创建控制台程序 2.设置项目的.net 版本 3.创建Ado.net实体数据模型 3.打开实体数据模型向导Entity Framework有四种模型选择 来自数据库的EF设计器(Da ...

  2. Entity Framework Tutorial Basics(5):Create Entity Data Model

    Create Entity Data Model: Here, we are going to create an Entity Data Model (EDM) for SchoolDB datab ...

  3. Create Entity Data Model

    http://www.entityframeworktutorial.net/EntityFramework5/create-dbcontext-in-entity-framework5.aspx 官 ...

  4. EF中的实体类型【Types of Entity in Entity】(EF基础系列篇8)

    We created EDM for existing database in the previous section. As you have learned in the previous se ...

  5. 3.翻译:EF基础系列--EF怎么工作的?

    原文链接:http://www.entityframeworktutorial.net/basics/how-entity-framework-works.aspx 这里,你将会大概了解到EF是怎么工 ...

  6. 实体之间的关系【Entity Relationships】(EF基础系列篇9)

    Here, you will learn how entity framework manages the relationships between entities. Entity framewo ...

  7. 1.翻译:EF基础系列--什么是Entity Framework?

    大家好,好久不见,EF系列之前落下了,还是打算重新整理一下. 先说说目前的打算:先简单了解一下EF基础系列-->然后就是EF 6 Code-First系列-->接着就是EF 6 DB-Fi ...

  8. 数据上下文【 DnContext】【EF基础系列7】

    DBContext: As you have seen in the previous Create Entity Data Model section, EDM generates the Scho ...

  9. Entity Framework 教程——创建实体数据模型

    创建实体数据模型: 本文将带你创建实体数据模型(EDM)SchoolDB数据库和理解基础建设模块. 实体数据模型(EDM)是用于描述实体之间关系的一种模型,以下将使用Visual Studio 201 ...

随机推荐

  1. CYQ.Data V5 从入门到放弃ORM系列:框架的优势

    前言: 框架开源后,学习使用的人越来越多了,所以我也更加积极的用代码回应了. 在框架完成了:数据库读写分离功能 和 分布式缓存功能 后: 经过三天三夜的不眠不休,终于完成框架第三个重量级的功能:自动化 ...

  2. 解读ASP.NET 5 & MVC6系列(3):项目发布与部署

    本章我们将讲解ASP.NET5项目发布部署相关的内容,示例项目以我们前一章创建的BookStore项目为例. 发布前的设置 由于新版ASP.NET5支持多版本DNX运行环境的发布和部署,所以在部署之前 ...

  3. ABP理论学习之Abp Session

    返回总目录 本篇目录 介绍 注入Session 使用Session属性 介绍 当应用程序要求用户登录时,那么应用程序也需要知道当前用户正在执行的操作.虽然ASP.NET本身在展现层提供了Session ...

  4. 关于大型网站技术演进的思考(二十)--网站静态化处理—web前端优化—中(12)

    Web前端很多优化原则都是从如何提升网络通讯效率的角度提出的,但是这些原则使用的时候还是有很多陷阱在里面,如果我们不能深入理解这些优化原则背后所隐藏的技术原理,很有可能掉进这些陷阱里,最终没有达到最佳 ...

  5. 在C#代码中应用Log4Net(三)Log4Net中配置文件的解释

    一个完整的配置文件的例子如下所示,这个是”在C#代码中应用Log4Net(二)”中使用的配置文件. <log4net> <!-- 错误日志类--> <logger nam ...

  6. Linux 查找已安装软件的方法

    1.rpm 注意rpm区分大小写 查询已安装的以mysql开头的包 rpm  -qa mysql* 查询已安装的mysql 包 rpm -qa|grep mysql rpm的方法有时候也所有已安装的包 ...

  7. 深入浅出Alljoyn——实例分析之远程调用(Method)篇

    深入浅出就是很深入的学习了很久,还是只学了毛皮,呵呵! 服务端完整代码: #include <qcc/platform.h> #include <assert.h> #incl ...

  8. Java 8函数编程轻松入门(二)Stream的使用

    在C#中,微软基于IEnumerable接口,提供许多便捷的扩展方法,便于实际的开发.在Java 1.8中,Collection接口新增了default stream方法.我们可以针对java集合,在 ...

  9. Socket programing(make a chat software) summary 1:How to accsess LAN from WAN

    First we should know some basic conceptions about network: 1.Every PC is supposed to have its own IP ...

  10. JQuery学习思维导图版

    常用UI资源 参考资料:Jquery教程 dataTables:教程  中文教程 Wizard:教程 Jquery UI demos:教程 selectmenu:教程 jquery-slider:教程 ...