当前位置: 首页 > 编程语言 > C# > 正文

C# 3.0入门系列(七)--之OR工具介绍(上)

时间:2010-06-13 博客园 Tom Song

……不得不再次给关注dlinq的朋友道歉了。好久都没有更新blog了。因为工作的变动,还要赶期限,没有时间关注这里了。

先发布一则消息。Orcas Beta1, 这个才是beta1,可以到http://www.microsoft.com/downloads/details.aspx?FamilyID=f10fb5df-e369-4db4-b9a7-845dbf793368&DisplayLang=en 下载。5月1号的版本。最早4月19号就出来过一个,只是没有在意。还有一个http://www.microsoft.com/downloads/details.aspx?FamilyID=36b6609e-6f3d-40f4-8c7d-ad111679d8dc&DisplayLang=en 。 一个是self-extracting 版本的,一个是Virtual PC version的。不知道什么区别。没有装过。

本节舍去原来的计划,而改讲映射工具。在入门三一文中,我们提到了sqlmetal这个工具。http://www.cnblogs.com/126/archive/2006/09/06/492332.html sqlmetal的功能是将数据库的信息抽提出来,生成映射代码。Orcas还有另外一个工具,就是O/R Designer.

先讲sqlmetal. 自上次的版本后,sqlmetal,又增加了一些新的功能。比如,支持SQLCE版本的Sql Server, 支持直接输入connection string, 等等。 这是sqlmetal的帮助信息,是不是比上次多了很多?

Microsoft (R) Database Mapping Generator 2008 Beta 2 version 1.00.20612
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.

SqlMetal [options] [<input file>]

 Generates code and mapping for the LINQ to SQL component of the .NET framework. SqlMetal can:
 - Generate source code and mapping attributes or a mapping file from a database.
 - Generate an intermediate dbml file for customization from the database.
 - Generate code and mapping attributes or mapping file from a dbml file.

Options:
 /server:<name>       Database server name.
 /database:<name>      Database catalog on server.
 /user:<name>        Login user ID (default: use Windows Authentication).
 /password:<password>    Login password (default: use Windows Authentication).
 /conn:<connection string> Database connection string. Cannot be used with /server, /database, /us
er or /password options.
 /timeout:<seconds>     Timeout value to use when SqlMetal accesses the database (default: 0 wh
ich means infinite).

 /views           Extract database views.
 /functions         Extract database functions.
 /sprocs          Extract stored procedures.

 /dbml[:file]        Output as dbml. Cannot be used with /map option.
 /code[:file]        Output as source code. Cannot be used with /dbml option.
 /map[:file]        Generate mapping file, not attributes. Cannot be used with /dbml option
.

 /language:<language>    Language for source code: VB or C# (default: derived from extension on code file name).
 /namespace:<name>     Namespace of generated code (default: no namespace).
 /context:<type>      Name of data context class (default: derived from database name).
 /entitybase:<type>     Base class of entity classes in the generated code (default: entities have no base class).
 /pluralize         Automatically pluralize or singularize class and member names using English language rules.
 /serialization:<option>  Generate serializable classes: None or Unidirectional (default: None).
 /provider:<type>      Provider type (default: provider is determined at run time).

 <input file>        May be a SqlExpress mdf file, a SqlCE sdf file, or a dbml intermediate file.

Create code from SqlServer:
 SqlMetal /server:myserver /database:northwind /code:nwind.cs /namespace:nwind

Generate intermediate dbml file from SqlServer:
 SqlMetal /server:myserver /database:northwind /dbml:northwind.dbml /namespace:nwind

Generate code with external mapping from dbml:
 SqlMetal /code:nwind.cs /map:nwind.map northwind.dbml

Generate dbml from a SqlCE sdf file:
 SqlMetal /dbml:northwind.dbml northwind.sdf

Generate dbml from SqlExpress local server:
 SqlMetal /server:.\sqlexpress /database:northwind /dbml:northwind.dbml

Generate dbml by using a connection string in the command line:
 SqlMetal /conn:"server='myserver'; database='northwind'" /dbml:northwind.dbml