How to: Generate the Object Model in Visual Basic or C# (LINQ to SQL)
In LINQ to SQL, an object model in your own programming language is mapped to a relational database. Two tools are available for automatically generating a Visual Basic or C# model from the metadata of an existing database.
If you are using Visual Studio, you can use the Object Relational Designer to generate an object model. The O/R Designer provides a rich user interface to help you generate a LINQ to SQL object model. For more information, see Object Relational Designer (O/R Designer) and Object Relational Designer (O/R Designer).
The SQLMetal command-line tool. For more information, see SqlMetal.exe (Code Generation Tool).
Note
If you do not have an existing database and want to create one from an object model, you can create your object model by using your code editor and CreateDatabase. For more information, see How to: Dynamically Create a Database (LINQ to SQL).
Documentation for the O/R Designer provides examples of how to generate a Visual Basic or C# object model by using the O/R Designer. For more information, see Object Relational Designer (O/R Designer) and Object Relational Designer (O/R Designer). The following information provide examples of how to use the SQLMetal command-line tool. For more information, see SqlMetal.exe (Code Generation Tool).
Example
The SQLMetal command line shown in the following example produces Visual Basic code as the attribute-based object model of the Northwind sample database. Stored procedures and functions are also rendered.
sqlmetal /code:northwind.vb /language:vb "c:\northwnd.mdf" /sprocs /functions
The SQLMetal command line shown in the following example produces C# code as the attribute-based object model of the Northwind sample database. Stored procedures and functions are also rendered, and table names are automatically pluralized.
sqlmetal /code:northwind.cs /language:csharp "c:\northwnd.mdf" /sprocs /functions /pluralize
See Also
Reference
Attribute-Based Mapping (LINQ to SQL)
SqlMetal.exe (Code Generation Tool)
External Mapping Reference (LINQ to SQL)
Concepts
Learning by Walkthroughs (LINQ to SQL)
Downloading Sample Databases (LINQ to SQL)
Other Resources
Programming Guide (LINQ to SQL)
How to: Customize Entity Classes by Using the Code Editor (LINQ to SQL)