Create an object model using LINQ to SQL

Source: Internet
Author: User

In LINQ to SQL, use your own programming language to map object models to relational databases. two tools are available to automatically generate a visual basic or C # model using the metadata of an existing database

    • Sqlmetal command line tool
    • If you are using Visual Studio, you can use the object relationship designer to generate an object model.
The sqlmetal command line shown in the following example will generate C #CodeThis is an attribute-based object model of the northwind sample database. It also presents stored procedures and functions and automatically converts the table name to the plural form (/pluralize )
 
Sqlmetal/code: northwind. CS/language: CSHARP "C: \ northwnd. MDF"/sprocs/functions/pluralize

As an alternative to property-based ing, you can use the sqlmetal command line tool to generate your object model as an external XML file,Using External XML ing files can reduce code confusion. You can also modify the behavior of an external file without re-compiling the application.ProgramThe following command generates an external ing file from the northwind sample database:

 

 
Sqlmetal/Server: myserver/Database: northwind/code: innerfile. CS/map: externalfile. xml

 

You can generate visual basic or C # From the metadata file of the database Markup Language (. dbml #Source code. This method provides an opportunity to customize the default. dbml file before generating the application ing code. This is an advanced function. before using this function, you need to generate a. dbml file,

 

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

 

Now that the. dbml file is available, we can customize the default. dbml file. After the modification, we will continue to use the sqlmetal command to generate the CS model.

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




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.