To Implement LINQ to SQL first we have to create the DBML file, the DBML file contains the C# source code which allow us to write the LINQ Queries to SQL. Here is the step by step process to generate dbml file.
Right click on the project (or project folder) and select the option Add New Item.
Select LINQ to SQL Classes Template and Give Name as MyDB.dbml.
Click on Yes when the below confirmation displayed.
MyDB.dbml file will be added under App_Code folder.
Expand Server Explorer and Right click on the Data Connections and select the option Add Connection.
Add Connection Pop up will be opened, give the SQL Server details and select the then click on OK button.
Database will be added under Data Connections as shown below.
Drag the table in the left pane and if primary key & foreign key relations are there then it will automatically show as shown below.
Drag the stored procedures to the right pane.
Related C# code will be automatically generated and we can see by opening the file MyDB.designer.cs.
No comments:
Post a Comment