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. ios --- 调用系统"设置"里的功能(转)

    安装后第一次运行软件时,系统会弹出提示用户是否允许软件获取当前位置,如果用户不允许的话,之后运行时系统不会在弹出提示设置,这点很不方便,有个解决办法是给用户一个选项,调出iphone中“设置”定位服务 ...

  2. Codeforces Round #254(div2)A

    很有趣的题.想到了就非常简单,想不到就麻烦了. 其实就是一种逆向思维:最后结果肯定是这样子: WBWBWBWB... BWBWBWBW... WBWBWBWB... ... 里面有“-”的地方改成“- ...

  3. django的settings文件

    转载:http://www.cnblogs.com/likeshan168/articles/3596344.html

  4. <Yii 学习>写入日志

    $postStr ='test:'.(empty( $GLOBALS["HTTP_RAW_POST_DATA"])?'':$GLOBALS["HTTP_RAW_POST_ ...

  5. NSString *const 和 const NSString * 的区别

    1.变量存储的指针可变,变量存储的值不可变 //A modifiable pointer to a constant NSString (its value can't be modified) &q ...

  6. Mxgraph使用总结一

    一.Mxgraph介绍: mxGraph 是一个 JS 绘图组件适用于需要在网页中设计/编辑 Workflow/BPM流程图.图表.网络图和普通图形的 Web 应用程序.mxgraph 下载包中包括j ...

  7. object.observe数据绑定

    object.observe方法格式如下: object.observe(object,callback) 监听object对象,当该对象有新增或更新或删除等操作,就会触发callback,就实现了双 ...

  8. 应用层-day01

    主流应用程序体系结构:CS结构.P2P结构. CS结构:客户-服务器体系结构.有一台总是打开的主机称为服务器,它服务来自其他许多称为客户的主机的请求. P2P体系结构:应用程序在不同的主机间链接,被称 ...

  9. asp.net自动将页面中的所有空间置为不可用以及将所有文本框置空

    /// <summary> /// 遍历页面上所有控件 /// </summary> /// <param name="page">指定的Pag ...

  10. 使用jQuery+css实现选项卡切换功能

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...