Sqlmetal Code Generation Tool

Source: Internet
Author: User

The sqlmetal command line tool can generate code and ing for the. NET Framework's LINQ to SQL component. By applying the options next to this topic, you can instruct sqlmetal to perform several different operations, including:

  • Generate source code and ing properties or ing files from the database.

  • Generate an intermediate database Markup Language (. dbml) file for custom use from the database.

  • Generate code and ing attributes or ing files from the. dbml file.

By default, the sqlmetal file is located under drive: "Program Files" Microsoft sdks "Windows" VN. nn "bin.

sqlmetal [options] [<input file>]
Option

To view the latest Option List, enter sqlmetal /? .

Connection options

Option

Description

/Server:<Name>

Specify the name of the database server.

/Database:<Name>

Specifies the database directory on the server.

/User:<Name>

Specify the logon user ID. Default Value: Windows authentication.

/Password:<Password>

Specify the logon password. Default Value: Windows authentication.

/Conn:<Connection string>

Specifies the database connection string. Cannot match/Server,/Database,/UserOr/PasswordOption.

Do not include the file name in the connection string. Instead, the file name should be added to the command line as the input file. For example, the following command specifies "C:" northwnd. MDF "as the input file:Sqlmetal/Code: "C:" northwind. cs "/language: CSHARP" C: "northwnd. MDF".

/Timeout:<Seconds>

Specifies the timeout value when sqlmetal accesses the database. Default Value: 0 (no time limit ).

Extraction options

Option

Description

/Views

Extract the database view.

/Functions

Extract database functions.

/Sprocs

Extract the stored procedure.

Output options

Option

Description

/Dbml[: File]

Send the output with the. dbml extension. Cannot match/MapOption.

/Code[: File]

Send the output as source code. Cannot match/DbmlOption.

/Map[: File]

Generate an XML ing file instead of an attribute. Cannot match/DbmlOption.

Miscellaneous

Option

Description

/Language:<Language>

Specifies the source code language.

Valid <language> include: VB and CSHARP.

Default Value: Derived from the code file extension.

/Namespace:<Name>

Specify a namespace for the generated code. Default Value: No namespace.

/Context:<Type>

Specifies the name of the data context class. Default Value: Derived from the database name.

/Entitybase:<Type>

Specify the base class for the entity class in the generated code. Default Value: the object does not have a base class.

/Pluralize

Automatically applies the plural or singular form to the class and member names.

This option is only available in English (us.

/Serialization:<Option>

Generate serializable classes.

Valid <option> options include none and unidirectional. Default Value: none.

For more information, see serialization (LINQ to SQL ).

Input File

Option

Description

<Input File>

Specify the SQL Server Express. MDF file, SQL Server compact 3.5. SDF file, or. dbml intermediate file.

Remarks

The sqlmetal function involves two steps:

  • Extract the metadata of the database to A. dbml file.

  • Generate a code output file.

    You can use appropriate command line options to generate visual basic or C # source code, or an XML ing file.

To extract metadata from the. MDF file, you must specify the name of the. MDF file after all other options.

If not specified/ServerIs assumed to beLocalhost/sqlexpress.

If one or more of the following conditions exist, Microsoft SQL Server 2005 will cause an exception:

  • Sqlmetal tries to extract the Stored Procedure for self-calling.

  • The nesting level of stored procedures, functions, or views exceeds 32.

    Sqlmetal will capture this exception and report it as a warning.

To specify an input file name, add the name as the input file to the command line. The file name cannot be included in the connection string./ConnOption ).

Generate a. dbml file containing the extracted SQL metadata:

Sqlmetal/Server: myserver/Database: northwind/dbml: mymeta. dbml

Use SQL Server express to generate a. dbml file that contains the SQL metadata extracted from the. MDF file:

S qlmetal/dbml: mymeta. dbml mydbfile. MDF

Generate a. dbml file that contains SQL metadata extracted from SQL Server Express:

Sqlmetal/Server:. "sqlexpress/dbml: mymeta. dbml/Database: northwind

Source code generated based on the. dbml metadata file:

Sqlmetal/namespace: nwind/code: nwind. CS/language: CSHARP mymetal. dbml

Generate Source Code directly based on SQL metadata:

Sqlmetal/Server: myserver/Database: northwind/namespace: nwind/code: nwind. CS/language: CSHARP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.