To create an .edmx file from an existing database

  1. Open or create the project for which you want to create an .edmx file.

  2. Right-click the project name in Solution Explorer, point to Add, and then click New Item.

  3. Select ADO.NET Entity Data Model in the Templates pane.

  4. Enter the name for the file (<project name>.edmx), and then click Add.

    The first page of the Entity Data Model Wizard appears.

  5. Select Generate from database in the Choose Model Contents dialog box, and then click Next.

  6. Click the New Connection button.

    The Connection Properties dialog box appears.

  7. Enter the server name, select the authentication method, and enter the name of the database for which the model is being created. Click OK.

    The Choose Your Data Connections dialog box is updated with the database connection settings.

    NoteNote

    By default, entity connection settings are saved in the App.config or Web.config file (depending on the project type). Type a name for the connection or use the provided default name. Clear the Save entity connection settings check box if you do not want connection information saved in a configuration file. For more information about saving connection settings, see Choose Your Data Connection Dialog Box (Entity Data Model Wizard).

  8. Click Next to continue.

    The Choose Your Database Objects dialog box appears. By default, no objects in the database are selected for inclusion in the .edmx file.

  9. Expand the nodes for Tables, Views, and Stored Procedures. Cancel the selection of any tables, views, and stored procedures that you do not want included in the .edmx file.

    NoteNote

    Classes generated from the conceptual model will be in the Model Namespace. Type a name for the namespace or use the provided default name. For more information, see Generated Code Overview (Entity Data Model Designer).

  10. Click Finish to create the .edmx file.

    The Entity Data Model Wizard does the following:

    • Adds references to the System.Data, System.Data.Entity, System.Core, System.Security, and System.Runtime.Serialization assemblies to the project, if they do not already exist.

    • Generates an .edmx file that encapsulates the storage model, the conceptual model, and mappings.

    • Creates a source code file that contains classes generated from the conceptual model. You can view the source code file by expanding the .edmx node in Solution Explorer. To see the source code file in Visual Basic projects, you must click the Show All Files button inSolution Explorer before you expand the .edmx node.

    NoteNote

    The source code file is generated from the .edmx file. Any manual changes to the source code file are overwritten when the corresponding .edmx file changes. To prevent custom code from being overwritten, you can write partial classes that are stored in separate files. For more information, see Customizing Objects (Entity Framework).

    • Creates an App.Config or Web.Config file (depending on the project type).

    • For ASP.NET Website projects, defines a build provider in the Web.config file.

    • Displays the conceptual model in the ADO.NET Entity Data Model Designer (Entity Designer). For information about how to modify your model with the Entity Designer, see Entity Data Model Tools Tasks and Entity Data Model Tools Scenarios.

For an example of creating an actual model from an existing database, see Quickstart (Entity Framework).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值