21 February 2014

How to Creating DBML in asp.net

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.

add-new-item

Select LINQ to SQL Classes Template and Give Name as MyDB.dbml.

linq-to-sql-classess

Click on Yes when the below confirmation displayed.

dialog

MyDB.dbml file will be added under App_Code folder.

dbml

Expand Server Explorer and Right click on the Data Connections and select the option Add Connection.

add-connection

Add Connection Pop up will be opened, give the SQL Server details and select the then click on OK button.

server-detail

Database will be added under Data Connections as shown below.

server-explorer

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-tables

Drag the stored procedures to the right pane.

drag-store-procedures

Related C# code will be automatically generated and we can see by opening the file MyDB.designer.cs.

dbml-designer-cs

No comments:

Post a Comment