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 ...
随机推荐
- hdu4451 Dressing(容斥原理)
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...
- java-05String课堂练习
1.阅读以下代码查看输出结果 public class StringPool { public static void main(String args[]) { String s0="He ...
- mapreduce-实现多表关联
//map package hadoop3; import java.io.IOException; import org.apache.hadoop.io.LongWritable;import o ...
- SpringMVC概要总结
架构流程 1. 用户发送请求至前端控制器DispatcherServlet 2. DispatcherServlet收到请求调用HandlerMapping处理器映射器. 3. 处理器映射器根据 ...
- 13.Selenium不再支持PhantomJS
在网上查看Selenium教程,发现很多都是使用PhantomJS进行爬虫,故想学习下,下载好了PhantomJS,配好了环境变量,编写代码后发现以下错误 from selenium import w ...
- Visualforce入门第二篇_2017.3.1
代码实现类似Html的表单(Form) <apex:page sidebar="false" standardController="Account"&g ...
- 记录启用HTTPS的全过程
因为 https 采用 ssl 加密,所以部署 https 时需要申请证书,证书的作用就是对浏览器和Web服务器双方的身份验证. 步骤1:申请证书 我们采用Let's Encrypt签发的免费证书,虽 ...
- Java基础--反射Reflection
Reflection 反射能在运行时获取一个类的全部信息,并且可以调用类方法,修改类属性,创建类实例. 而在编译期间不用关心对象是谁 反射可用在动态代理,注解解释,和反射工厂等地方. -------- ...
- (转)list_orderby
本文转载自:http://blog.csdn.net/liyifei21/article/details/6558098 一个条件排序情况 list.OrderBy(item => tem.St ...
- django的settings.py设置static
DEBUG = True ################ STATICFILES ################ # A list of locations of additional stati ...