Free Hit Counters
http://www.dellasdeals.com

[翻译]ADO.NET Entity Framework Beta2(八)/快速入门(实体框架)(3)/生成学校实体数据模型

In this task, you will learn to use the Entity Data Model Wizard to generate a set of 1:1 entity-to-table mapping files for the School model. The School model is used throughout the Entity Framework getting started documentation.

在本任务中,你将学习使用实体数据模型向导来为学校模型生成实体与表一一对应的映射文件。这个学校模型在 实体框架开始文档中被提出。

To add the ADO.NET Entity Data Model item template/添加ADO.NET 实体数据模型项模板

  1. Select the ClassSchedule project in the Solution Explorer, right-click, point to Add, and then click New Item.
    解决方案资源管理器中选中ClassSchedule项目,右击鼠标,选择添加,再选择新建项

  2. Select ADO.NET Entity Data Model in the Templates pane.
    在模板面板内选择ADO.NET Entity Data Model

  3. Type School.csdl for the model name and click Add.
    给模型命名叫School.csdl,然后点添加(实际情况是我看见的默认文件后缀是.edmx)

    The opening page of the Entity Data Model Wizard is displayed.
    本操作将启动实体数据模型向导。(上面的后缀就用默认的edmx,向导一样出来的)

To generate the EDM Files/生成EDM文件

  1. Select Generate from database in the Choose Model Contents dialog box. Then click Next.
    选择模型内容对话框内选择从数据库生成,然后单击下一步

  2. Click the New Connection button.
    单击新建连接按钮

    The Connection Properties dialog box is displayed.
    连接属性对话框被显示出来。

  3. Enter your server name, select the authentication method, type School for the database name, and then click OK.
    输入你的数据库服务器实例名,选则登陆验证方式,输入已经创建的数据库名School,然后点击确定。

    The Choose Your Data Connections dialog box is updated with your database connection settings.
    根据你选择的数据连接设置,选择数据连接的对话框内容被更新。

  4. Ensure that Save entity connection settings in App.Config as: is checked and the value is set to SchoolModel. Then click Next.
    检查确认将实体连接字符串保存到App.Config复选框已经被打上钩,并且文本框内的值是SchoolModel(实际操作时名称是SchoolEntites).单击下一步。

    The Choose Your Database Objects dialog box is displayed.
    选择你的数据库对象对话框被现实。(这个时候下面的文本框内容倒是SchoolModel)

  5. Ensure that all tables are selected, and then click Finish to complete the wizard.
    确认所有的表都被选中了。然后单击结束按钮以完成整个向导。

    The wizard does the following:
    向导为我们做了下列事情:

    • Adds references to the System.Data and System.Data.Entity namespaces.
      添加了对System.Data和System.Data.Entity命名空间的引用
    • Generates .csdl, .ssdl, and .msl files.
      生成.csdl、.ssdl和.msl文件

    • Creates a source code file that contains the classes that were generated from the .csdl file. You can view the source code file by expanding the .csdl file in the Solution Explorer.
      创建了一个源码文件包含了根据.csdl文件生成的类代码。你可以通过展开解决方案管理器里的.csdl文件来查看这些源文件。

    Note /注意
    In Visual Basic projects, you must press the Show All Files button in the Solution Explorer before you can view the source code. 在VB项目中,你必须使用 显示所有文件 按钮 在解决方案资源管理器 中 才能看到这些源代码。 
    • Creates an App.Config file.
      创建了一个App.Config文件。

Next Steps/下一步

You have successfully generated the mapping files and class definitions for the School model in the ClassSchedule project. Next, you will create queries against CLR objects that represent entities and associations in the School model:

你已经成功的为ClassSchedule项目的学校模型生成了映射文件和有关的类定义。下一步,你将创建基于CLR对象的查询来查询学校模型中的实体和关系。

Querying Entities and Associations/查询实体和关系

See Also/请参考

Concepts/概念

Generating an Entity Data Model/生成实体数据模型
Mapping a Conceptual Model to a Storage Schema/将概念模型映射到存储架构

Other Resources/其他资源

Walkthrough: Using the Entity Data Model Wizard
Feature Reference (Entity Framework)/功能参考(实体框架)

 

posted @ 2007-09-26 12:18  徐少侠  阅读(2162)  评论(3编辑  收藏  举报
作者:徐少侠 出处:http://www.cnblogs.com/Chinese-xu/

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过 Chinese_Xu@126.com 联系我,非常感谢。