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