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的更多相关文章

  1. Entity Framework Tutorial Basics(6):Model Browser

    Model Browser: We have created our first Entity Data Model for School database in the previous secti ...

  2. Entity Framework Tutorial Basics(1):Introduction

    以下系列文章为Entity Framework Turial Basics系列 http://www.entityframeworktutorial.net/EntityFramework5/enti ...

  3. 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 ...

  4. Entity Framework Tutorial Basics(43):Download Sample Project

    Download Sample Project: Download sample project for basic Entity Framework tutorials. Sample projec ...

  5. 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 ...

  6. Entity Framework Tutorial Basics(41):Multiple Diagrams

    Multiple Diagrams in Entity Framework 5.0 Visual Studio 2012 provides a facility to split the design ...

  7. Entity Framework Tutorial Basics(37):Lazy Loading

    Lazy Loading: One of the important functions of Entity Framework is lazy loading. Lazy loading means ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. uva1315 Crazy tea party(找规律)

    题意就是说把顺时针排的1到n换成逆时针排的需要的最少交换步数. 如果是线形的一串数,需要的交换次数就是个冒泡排序的交换次数:n*(n-1)/2,或者用a[i]=(i-1)+a[i-1]推出来. 对于环 ...

  2. UVA - 1608 Non-boring sequences (分治,中途相遇法)

    如果一个序列中是否存在一段连续子序列中的每个元素在该子序列中都出现了至少两次,那么这个序列是无聊的,反正则不无聊.给你一个长度为n(n<=200000)的序列,判断这个序列是否无聊. 稀里糊涂A ...

  3. [BZOJ4573][ZJOI2016]大♂森林

    bzoj luogu uoj sol \(orz\ \ HJT\ \ dalao\)教会我做这道题. 考虑每两个相邻位置的树的差异. 对于一个1操作(更换生长节点),假设区间是\([l,r]\),那么 ...

  4. http请求在asp.net中的请求过程

    当请求一个*.aspx文件的时候,这个请求会被inetinfo.exe进程截获,它判断文件的后缀(aspx)之后,将这个请求转交给 ASPNET_ISAPI.dll,ASPNET_ISAPI.dll会 ...

  5. mysql之 MySQL 主从基于position复制原理概述

    1 .主从复制简介MySQL 主从复制就是将一个 MySQL 实例(Master)中的数据实时复制到另一个 MySQL 实例(slave)中,而且这个复制是一个异步复制的过程.实现整个复制操作主要由三 ...

  6. webrtc windows下的编译

    mkdir webrtc-checkoutcd webrtc-checkout set DEPOT_TOOLS_WIN_TOOLCHAIN=0set GYP_GENERATORS=ninjaset G ...

  7. RuPengWang项目

    项目 Day1------------------------- 说明:建外键约束.ashx+Razor RupengWang创建三个类库Model DAL BLL后台:RupengWang.Admi ...

  8. 非常不错的LTE架构讲解

    <LTE系统协议架构---通俗易懂超经典> <3GPP协议导读> <3GPP协议36211-850中文翻译> <LTE全套协议汇总> <NB-IO ...

  9. 解决webpack因新版本打包失败问题--ERROR in multi ./src/main.js ./dist/bundle.js

    最近在学习webpack打包过程中遇到的一个问题向大家分享下! 创建了一个webpacksty的目录,目录下放着dist,src子目录,然后通过node环境下,npm init -y 初始化项目出现p ...

  10. 开发环境入门 linux基础 (部分)awk 赋值变量 if

    awk 常用于处理格式非常明显的文件 awk -F: '{print $1}' /etc/passwd  含义:取冒号分隔符的第一段内容 $0 指取所有! NF 指有几段内容 $NF 取最后一段内容 ...