| title | How to: Generate the Object Model in Visual Basic or C# | |
|---|---|---|
| ms.custom | ||
| ms.date | 03/30/2017 | |
| ms.prod | .net-framework | |
| ms.reviewer | ||
| ms.suite | ||
| ms.technology |
|
|
| ms.tgt_pltfrm | ||
| ms.topic | article | |
| ms.assetid | a0c73b33-5650-420c-b9dc-f49310c201ee | |
| caps.latest.revision | 3 | |
| author | douglaslMS | |
| ms.author | douglasl | |
| manager | craigg | |
| ms.workload |
|
In [!INCLUDEvbtecdlinq], an object model in your own programming language is mapped to a relational database. Two tools are available for automatically generating a [!INCLUDEvbprvb] or C# model from the metadata of an existing database.
-
If you are using [!INCLUDEvs_current_short], you can use the [!INCLUDEvs_ordesigner_long] to generate an object model. The [!INCLUDEvs_ordesigner_short] provides a rich user interface to help you generate a [!INCLUDEvbtecdlinq] object model. For more information see, Linq to SQL Tools in Visual Studio.
-
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 xref:System.Data.Linq.DataContext.CreateDatabase%2A. For more information, see How to: Dynamically Create a Database.
Documentation for the [!INCLUDEvs_ordesigner_short] provides examples of how to generate a [!INCLUDEvbprvb] or C# object model by using the [!INCLUDEvs_ordesigner_short]. The following information provide examples of how to use the SQLMetal command-line tool. For more information, see SqlMetal.exe (Code Generation Tool).
The SQLMetal command line shown in the following example produces [!INCLUDEvbprvb] 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
Programming Guide
The LINQ to SQL Object Model
Learning by Walkthroughs
How to: Customize Entity Classes by Using the Code Editor
Attribute-Based Mapping
SqlMetal.exe (Code Generation Tool)
External Mapping
Downloading Sample Databases
Creating the Object Model