Entity Framework Tutorial Basics(12):Model First
Model First development with Entity Framework:
In the Model First approach, you create Entities, relationships, and inheritance hierarchies directly on the design surface of EDMX and then generate database from your model.
So, in the Model First approach, add new ADO.NET Entity Data Model and select Empty EF Designer model in Entity Data Model Wizard.
You can create an entity, association and inheritance on an empty designer by right clicking on designer surface -> Add New -> Entity.
In the Add Entity dialogue, enter name of the entity. Also you can change the default settings for Entity set and key property. We will keep the default settings as it is. Click OK to generate an entity.
You can also add properties in the generated entity by right clicking on entity - > Add New -> Scalar property.
Enter the name of scalar property as shown below.
In the same way, you can add other entities and associations using toolbox.
After creating the required entities, associations, and inheritance on the design surface of the empty model, you can use the designer's context menu option 'Generate database from model' to generate DDL script.
This will open Generate Database Wizard. You can select existing database or create a new connection by clicking on New Connection.. Select database server and enter the name of the database to create and then click OK. It will ask you for the confirmation for creating a new database. Click Yes to create a database.
Click Next to generate DDL for the DB model as shown below.
This will add ModelName.edmx.sql file in the project. You can execute DDL scripts in Visual Studio by opening .sql file -> right click -> Execute.
Now, you can generate context class and entities by right clicking on the designer and selecting Add Code Generation Item..
This will add (ModelName).Context.tt and (ModelName).tt with context class and entity classes as shown below.
So, in this way, you can design your DB model and then generate a database and classes based on the model. This is called the Model-First approach.
Visit MSDN for detailed information on Model-First approach.
Entity Framework Tutorial Basics(12):Model First的更多相关文章
- Entity Framework Tutorial Basics(6):Model Browser
Model Browser: We have created our first Entity Data Model for School database in the previous secti ...
- Entity Framework Tutorial Basics(1):Introduction
以下系列文章为Entity Framework Turial Basics系列 http://www.entityframeworktutorial.net/EntityFramework5/enti ...
- Entity Framework Tutorial Basics(4):Setup Entity Framework Environment
Setup Entity Framework Environment: Entity Framework 5.0 API was distributed in two places, in NuGet ...
- Entity Framework Tutorial Basics(43):Download Sample Project
Download Sample Project: Download sample project for basic Entity Framework tutorials. Sample projec ...
- Entity Framework Tutorial Basics(42):Colored Entity
Colored Entity in Entity Framework 5.0 You can change the color of an entity in the designer so that ...
- Entity Framework Tutorial Basics(41):Multiple Diagrams
Multiple Diagrams in Entity Framework 5.0 Visual Studio 2012 provides a facility to split the design ...
- Entity Framework Tutorial Basics(37):Lazy Loading
Lazy Loading: One of the important functions of Entity Framework is lazy loading. Lazy loading means ...
- Entity Framework Tutorial Basics(36):Eager Loading
Eager Loading: Eager loading is the process whereby a query for one type of entity also loads relate ...
- Entity Framework Tutorial Basics(34):Table-Valued Function
Table-Valued Function in Entity Framework 5.0 Entity Framework 5.0 supports Table-valued functions o ...
随机推荐
- C8051F340 USB Fn hacking
/************************************************************************************ * C8051F340 US ...
- PHP提供的数组比较函数总结
在我们看PHP手册的时候发现,PHP提供了许多数组元素比较的函数,看起来又多又烦又不好记,现在我们来总结一下: sort() — 本函数对数组进行排序,当本函数结束时数组单元将被从最低到最高重新安排. ...
- Centos7 安装 MongoDB4.0
目录 安装包下载 MongoDB安装 启动数据库 补充 小结 诚邀访问我的个人博客:我在马路边 更好的阅读体验点击查看原文:Centos7安装MongoDB4.0 原创博客,转载请注明出处 @ 由于项 ...
- 异步通信rabbitmq——消息重试
目标: 利用RabbitMQ实现消息重试和失败处理,实现可靠的消费消费.在消息消费异常时,自动延时将消息重试,当重试超过一定次数后,则列为异常消息,等待后续特殊处理. 准备: TTL:Time-To- ...
- UGUI transform
在编辑器中将UGUI对象挂在另一个物体上,UGUI预制体根对象位置调成零,调好位置后保存 由gameframework初始化,再挂到对应父对象上时,位置会有偏差,会更改锚点旋转等信息,需在OnWind ...
- 伪元素after,before,css/js控制样式
CSS<style> body { font: 200%/1.45 charter; } ref::before { content: '\00A7'; letter-spacing: . ...
- Zabbix通过SNMPv2监控DELL服务器的硬件信息
(一)zabbix监控DELL服务器 (1)简述:监控DELL服务器硬件一般有两种途径:1.操作系统上安装OMSA,编写脚本调用omreport命令进行监控(需要在操作系统上安装比较麻烦):2.使用i ...
- es5中foreach的用法
HTML代码: <p id="result"></p> JS代码: var eleResult = document.getElementById(&quo ...
- Azure VM从ASM迁移到ARM(二)
在一中讨论了通过Azure平台的工具进行迁移的方案. 本文将讨论另外一种迁移方式.通过磁盘复制的方式,把部分VM迁移到ARM的Managed Disk模式. 一. 获得ASM中Disk的信息 在管理 ...
- -3dB的理解
-3dB到底是什么?集成运放-3dB带宽又是什么? 以无源高通电路为例,介绍-3dB的意义. 输出与输入只比: Au=Uo/Ui=R/(R+1/j*2*PI*f*C)=1/(1+1/j*2*PI*f* ...