In Visual Studio, on the File menu, point to New and then click Project. Select Visual Basic Windows Forms Application as the project type. On the Project menu, click Add New Item. Select the LINQ to SQL Classes item template. Name the file northwind.dbml. The Object Relational Designer (O/R Designer) opens for the northwind.dbml file. Yes I do have a Vs 2013 and dbml open in designer mode. – Drag and Drop Mar 28 '17 at 15:02. I've had issues with some designers when.
-->
LINQ to SQL classes that are mapped to database tables and views are called entity classes. The entity class maps to a record, whereas the individual properties of an entity class map to the individual columns that make up a record. Create entity classes that are based on database tables or views by dragging tables or views from Server Explorer or Database Explorer onto the LINQ to SQL tools in Visual Studio. The O/R Designer generates the classes and applies the specific LINQ to SQL attributes to enable LINQ to SQL functionality (the data communication and editing capabilities of the DataContext). For detailed information about LINQ to SQL classes, see The LINQ to SQL object model.
Note
The O/R Designer is a simple object relational mapper because it supports only 1:1 mapping relationships. In other words, an entity class can have only a 1:1 mapping relationship with a database table or view. Complex mapping, such as mapping an entity class to multiple tables, is not supported. However, you can map an entity class to a view that joins multiple related tables.
Create LINQ to SQL classes that are mapped to database tables or views
Dragging tables or views from Server Explorer or Database Explorer onto the O/R Designer creates entity classes in addition to the DataContext methods that are used for performing updates.
By default, the LINQ to SQL runtime creates logic to save changes from an updatable entity class back to the database. This logic is based on the schema of the table (the column definitions and primary key information). If you do not want this behavior, you can configure an entity class to use stored procedures to perform inserts, updates, and deletes instead of using the default LINQ to SQL run-time behavior. For more information, see How to: Assign stored procedures to perform updates, inserts, and deletes (O/R Designer).
Note
Your computer might show different names or locations for some of the Visual Studio user interface elements in this article. You may be using a different edition of Visual Studio or different environment settings. For more information, see Personalize the IDE.
To create LINQ to SQL classes that are mapped to database tables or views
In Server or Database Explorer, expand Tables or Views and locate the database table or view that you want to use in your application.
Drag the table or view onto the O/R Designer.
An entity class is created and appears on the design surface. The entity class has properties that map to the columns in the selected table or view.
Create an object data source and display the data on a form
After you create entity classes by using the O/R Designer, you can create an object data source and populate the Data Sources window with the entity classes.
To create an object data source based on LINQ to SQL entity classes
On the Build menu, click Build Solution to build your project.
To open the Data Sources window, on the Data menu, click Show Data Sources.
In the Data Sources window, click Add New Data Source.
Click Object on the Choose a Data Source Type page and then click Next.
Expand the nodes and locate and select your class.
Note
If the Customer class is not available, cancel out of the wizard, build the project, and run the wizard again.
Click Finish to create the data source and add the Customer entity class to the Data Sources window.
Drag items from the Data Sources window onto a form.
See also
-->
You can generate code to represent a database by using either the Object Relational Designer or the SQLMetal command-line tool. In either case, end-to-end code generation occurs in three stages:
The DBML Extractor extracts schema information from the database and reassembles the information into an XML-formatted DBML file.
The DBML file is scanned by the DBML Validator for errors.
If no validation errors appear, the file is passed to the Code Generator.
For more information, see SqlMetal.exe (Code Generation Tool). Developers using Visual Studio can also use the Object Relational Designer to generate code. See LINQ to SQL Tools in Visual Studio.
DBML Extractor
The DBML Extractor is a LINQ to SQL component that takes database metadata as input and produces a DBML file as output.
Code Generator
The Code Generator is a LINQ to SQL component that translates DBML files to Visual Basic, C#, or XML mapping files.
XML Schema Definition File
The DBML file must be valid against the following schema definition as an XSD file.
Distinguish this schema definition file from the schema definition file that is used to validate an external mapping file. For more information, see External Mapping).
Note
Visual Studio users will also find this XSD file in the XML Schemas dialog box as 'DbmlSchema.xsd'. To use the XSD file correctly for validating a DBML file, see How to: Validate DBML and External Mapping Files.
Sample DBML File
The following code is an excerpt from the DBML file created from the Northwind sample database. You can generate the whole file by using SQLMetal with the /xml option. For more information, see SqlMetal.exe (Code Generation Tool).