How to: Add LINQ to SQL Classes to a Project (O/R Designer)
Data classes (entity classes, associations, and DataContext methods) are defined in LINQ to SQL files (.dbml files) and created and edited in the Object Relational Designer (O/R Designer). You add LINQ to SQL files to projects by using the Add New Item dialog box and selecting the LINQ to SQL Classes template. For more information about data classes, see The LINQ to SQL Object Model.
Create and edit LINQ to SQL classes by using the O/R Designer.
Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Customizing Development Settings.
To add a LINQ to SQL file to a project
From within a Visual Basic or C# application, on the Project menu, click Add New Item.
Click the LINQ to SQL Classes template.
Either provide an alternative name or keep the default name of DataClasses1.dbml.
The name provided will be the name of the generated DataContext. For example, using the default name will cause the designer to name the DataContext DataClasses1DataContext.
The .dbml file is added to the project and the O/R Designer opens.
After you add a LINQ to SQL file to your project, the empty design surface represents a DataContext ready to be configured. Drag database items from Server Explorer/Database Explorer onto the O/R Designer to create data classes and DataContext methods. The data connection of a DataContext is created based on the first item added to the designer form Server Explorer/Database Explorer.
The following topics provide detailed instructions for creating LINQ to SQL classes and DataContext methods by using the O/R Designer.
Provides step-by-step directions for creating entity classes that map to tables and views in a database, including information about what is updateable and read only.
Provides step-by-step directions for creating DataContext methods that map to stored procedures and functions.
Describes how to create DataContext methods that replace the default save logic for an entity class with user-provided stored procedures.
Provides step-by-step instructions for designing entity classes by using the O/R Designer and for displaying data on a Windows Form.
Provides step-by-step directions for creating DataContext methods that replace the default save logic for an entity class with user-provided stored procedures.
Provides step-by-step directions for adding code to validate data.