In this post I will show you, how you could bind a Windows Form with Entity created by O/R designer. Essentially we are going to create a DataSource using generated entity of O/R designer.

I assume that,

1. You have created Windows Application project.

2. You have created Datacontext and entity class using LINQ to SQL class. Imagine you have dragged and dropped Person class on O/R designer from School database. Dbml file is looking more or less like below.

clip_image001

Follow the below steps to bind Windows Form,

1. Click on Data from top menu and choose Add New Data Source

clip_image002

2. Select Object as Data Source type

clip_image004

3. Choose Data object. Select Person from listed objects and click Finish

clip_image006

4. Navigate to Windows Form and open design surface and again click on Data in top menu and choose Show Data Sources

clip_image007

5. Now you will get Person in Data Sources listed. Select and drag on design surface.

clip_image009

In bottom of designer you can see Binding Data Source created

clip_image010

6. Now open the code Form class and add below code. Since you know to populate the data you need to set the Data Source of Binding Source as DataContext .

clip_image012

7. To save modification and add new rows , open Properties of Save button from navigation

clip_image013

Then in Properties Windows set Enabled as true.

clip_image014

8. In event of Save button write below code

clip_image016

Press F5 to run the application

clip_image017

Now you should able to perform all the operation.

I hope this post was useful. Thanks for reading Smile




Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to Yahoo BuzzAdd to Newsvine

Advertisements

3 thoughts on “Using O/R designer to bind a Windows Form in LINQ

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s