创建实体数据模型【Create Entity Data Model】(EF基础系列5)
现在我要来为上面一节末尾给出的数据库(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)的更多相关文章
- EntityFramework 学习 一 创建实体数据模型 Create Entity Data Model
1.用vs2012创建控制台程序 2.设置项目的.net 版本 3.创建Ado.net实体数据模型 3.打开实体数据模型向导Entity Framework有四种模型选择 来自数据库的EF设计器(Da ...
- 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 ...
- Create Entity Data Model
http://www.entityframeworktutorial.net/EntityFramework5/create-dbcontext-in-entity-framework5.aspx 官 ...
- 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 ...
- 3.翻译:EF基础系列--EF怎么工作的?
原文链接:http://www.entityframeworktutorial.net/basics/how-entity-framework-works.aspx 这里,你将会大概了解到EF是怎么工 ...
- 实体之间的关系【Entity Relationships】(EF基础系列篇9)
Here, you will learn how entity framework manages the relationships between entities. Entity framewo ...
- 1.翻译:EF基础系列--什么是Entity Framework?
大家好,好久不见,EF系列之前落下了,还是打算重新整理一下. 先说说目前的打算:先简单了解一下EF基础系列-->然后就是EF 6 Code-First系列-->接着就是EF 6 DB-Fi ...
- 数据上下文【 DnContext】【EF基础系列7】
DBContext: As you have seen in the previous Create Entity Data Model section, EDM generates the Scho ...
- Entity Framework 教程——创建实体数据模型
创建实体数据模型: 本文将带你创建实体数据模型(EDM)SchoolDB数据库和理解基础建设模块. 实体数据模型(EDM)是用于描述实体之间关系的一种模型,以下将使用Visual Studio 201 ...
随机推荐
- js 的一些知识 摘自http://img0.pconline.com.cn/Pc_intranet/1105/13/313647_7.pdf
Js 问题分析--js 影响页面性能现状分析:问题陈述分析问题:抽象问题根源,通过实例或推理证明问题的严重性问题引申:以现有问题为点开始扩散,这将导致其它什么问题,或同一类型的问题问题总结:从分散开始 ...
- GIT的认识
说实话,在听到小伙伴们都说赶紧做作业的时候很茫然,连一点头绪都没有,根本不知道从何入手,但不能因为不会就不去做,于是还是拿起手机,找到小伙伴商量着做着,虽然等的过程很焦急,但还是注册成功了.而开始写对 ...
- node(async原理)
node中的async是用来实现同步操作的,提供包括map.Series等方法,本文不做赘述. 由于项目需要在浏览器端用了async.js,因此仔细看了下它的代码.原来,一直以为node是在服务端调用 ...
- SQL Server 的 Statistics 簡介
當你要清空「資料表(table)」,或倒入大量「資料(data;record)」,或公司「資料庫(database)」改用新版本要資料大搬家…等情形,不只是要重建「索引(index)」,還應要重建或更 ...
- Android开发学习之路-Android Studio开发小技巧
上一次发过了一个介绍Studio的,这里再发一个补充下. 我们都知道,Android Studio的功能是非常强大的,也是很智能的.如果有人告诉你学Android开发要用命令行,你可以告诉他Andro ...
- sublime text 下的Markdown写作
sublime text 2(3)下的Markdown写作 什么是 Markdown wiki Markdown 是一种方便记忆.书写的纯文本标记语言,用户可以使用这些标记符号以最小的输入代价生成极富 ...
- 2013 duilib入门简明教程 -- 自绘控件 (15)
在[2013 duilib入门简明教程 -- 复杂控件介绍 (13)]中虽然介绍了界面设计器上的所有控件,但是还有一些控件并没有被放到界面设计器上,还有一些常用控件duilib并没有提供(比如 ...
- Base64编码原理分析
Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一,在了解Base64编码之前,先了解几个基本概念:位.字节. 位:"位(bit)"是计算机中最小的数据单位.每一位 ...
- 使用未付费的账号真机调试 iOS 程序,过几天后程序一打开就会闪退
使用未付费的苹果开发者账号真机调试 iOS 程序,过几天后程序一打开就会闪退. 解决办法: 删除 Provisioning Profile,重新配置一次. 终极解决办法:花钱购买苹果开发者账号. ...
- OLE DB Command transformation 用法
OLE DB Command transformation component 能够引用参数,逐行调用sqlcommand,This transformation is typically used ...