create LINQ to SQL classes

To access data in a SQL Server database using Language-Integrated Query, it is not possible to directly connect to the database. So, we create classes using the Object Relational Designer to represent database and tables. Using these classes we can retrieve, update and insert data in a database.

The Object Relational Designer provides a visual design interface to create LINQ to SQL classes that are based on objects like tables, stored procedures, views, functions in a database.

To create LINQ to SQL entity classes, select the LINQ to SQL classes template in the Add New Item dialog box. Give a name to the file as SalesDB.dbml. Click OK to add a file to the project. If you expand this file you will see a SalesDB.dbml.layout file and SalesDB.designer.cs file as shown in fig given below.



The .dbml.layout file is the visual interface on to which you can drag tables and stored procedures . The .designer.cs file includes the classes which are created in the previous step. When you open SalesDB.designer.cs file, you can see the entity classes for the Customer table. Observe that the class is mapped to the database table � Customer table and properties of the class lists the table columns.

The generated code contains :

1.The DataContext class 
2.A partial class called Customer. Every column in the table is represented by a properties in a class. [Table(Name="dbo.Customer")] public partial class Customer : INotifyPropertyChanging, INotifyPropertyChanged { private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty); private int _CustomerId; private string _Name; private string _Address;