zoukankan      html  css  js  c++  java
  • 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.

    Entity Framework Model first

    You can create an entity, association and inheritance on an empty designer by right clicking on designer surface -> Add New -> Entity.

    Entity Framework Model first

    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.

    Entity Framework Model first

    You can also add properties in the generated entity by right clicking on entity - > Add New -> Scalar property.

    Entity Framework Model first

    Enter the name of scalar property as shown below.

    Entity Framework Model first

    In the same way, you can add other entities and associations using toolbox.

    Entity Framework Model first

    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.

    Entity Framework Model first

    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.

    Entity Framework Model first

    Click Next to generate DDL for the DB model as shown below.

    Entity Framework Model first

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

    Entity Framework Model first

    This will add (ModelName).Context.tt and (ModelName).tt with context class and entity classes as shown below.

    Entity Framework Model first

    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.

  • 相关阅读:
    Vue 中动态添加class(使用v-bind:class)
    Vue 过滤器的使用
    Huxley 是一个用于Web应用 UI 测试的工具
    showmessage函数里
    [Php] PHPExcel读取Excel文件(或来自客户端上传的)并返回二维数组
    async-validator -- git地址
    Antd Upload组件上传文件至php后端, php拿到对应的文件名(二: vue实现)
    Antd Upload组件上传文件至php后端, php拿到对应的文件名
    对数据库中一个timestamp类型字段时间上作加减
    小学生作文怎么辅导?
  • 原文地址:https://www.cnblogs.com/purplefox2008/p/5648990.html
Copyright © 2011-2022 走看看