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 ...
随机推荐
- Codeforces Round #262 (Div. 2)C(二分答案,延迟标记)
这是最大化最小值的一类问题,这类问题通常用二分法枚举答案就行了. 二分答案时,先确定答案肯定在哪个区间内.然后二分判断,关键在于怎么判断每次枚举的这个答案行不行. 我是用a[i]数组表示初始时花的高度 ...
- [Unity3D]EZGUI 操作简单介绍
官方的GUI根本无法跟EZGUI比,无论是资源还是易用性还是速度.EZGUI基于Mesh不占DrawCall.EZGUI是自动合并Mesh成为一个物体,并且贴图自动制作Atlas.所以效率高,CPU消 ...
- 3143 codevs 二叉树的序遍历
题目描述 Description 求一棵二叉树的前序遍历,中序遍历和后序遍历 输入描述 Input Description 第一行一个整数n,表示这棵树的节点个数. 接下来n行每行2个整数L和R.第i ...
- JSplitPane的简单实现
import java.awt.Color; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.J ...
- 宝塔中的 base_opendir chattr
宝塔中的 base_opendir chattr base_opendir 目的是限制一些函数将手乱伸. 而宝塔中的自动配置的是 .user.ini,这个是文件是 +i ............ 这个 ...
- bzoj 4591 [Shoi2015]超能粒子炮·改——组合数前缀和
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4591 先说说自己的想法: 从组合意义的角度考虑,从n个里选<=k个,就添加k个空位置, ...
- hl7中V2版本的ACK消息的构造
hl7 v2的ack消息即应答消息构造时有几个注意的地方. 首先,我们看下2个ack的例子: Send: MSH|^~\&|NIST_SENDER^^|NIST^^|NIST_RECEIVER ...
- linux php相关命令
学习源头:http://www.cnblogs.com/myjavawork/articles/1869205.html php -m 查看php开启的相关模块 php -v 查看php的版本 运行直 ...
- 蓝桥杯 算法训练 ALGO-139 s01串
算法训练 s01串 时间限制:1.0s 内存限制:256.0MB 问题描述 s01串初始为”0” 按以下方式变换 0变1,1变01 输入格式 1个整数(0~19) 输出格式 n次变换后s01 ...
- Rails的静态资源管理(三)—— 开发环境的Asset Pipelin
官方文档:http://guides.ruby-china.org/asset_pipeline.html http://guides.rubyonrails.org/asset_pipeline.h ...